We're trying to move some keys and secrets from .env to AWS Parameter Store for better security. We have two EC2 instances, one for production env and another one for staging env. Each instance has keys/values defined in .env file below public folder, so it's hidden from public access.
Keys in .env file are identical between production and staging env, just values are different. So the code to load these values were the same between production and staging. Now that we're trying to move these keys/values to AWS Paramter Store, and since Parameter Store is account level scope,
Is there a way to assign different values based on EC2 instance?
e.g.
secret = getSecretFromEnv('MY_KEY'); // different values are loaded depending on EC2 instance
has become (what we're trying to avoid doing)
if prod {
secret = getSecureParameterFromAws('MY_PROD_KEY');
} else {
secret = getSecureParameterFromAws('MY_STAGING_KEY');
}