Creating process.env variables using AWS Amplify?
You can add variables at your Amplify environment configuration. You can also add variable overrides and select a branch that's gonna use it.
DOCS: https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
After a year+ of development using amplify framework I figured that you can only specify ENV VARIABLE form from your front-end build process. for lambdas it's a bit tricky. You can add a condition "IsProductionEnv"
which is going to place value to ENV Variables for that function depending on amplify env.
for production I use "prod"
you can use whatever you want.
go to your amplify/backend/function/{functionName}
folder.
there should be {functionName}-cloudformation-template.json
file.
you need to add one more item to "Conditions"
object:
"Conditions":{
...,
"IsProductionEnv": {
"Fn::Equals": [
{
"Ref": "env"
},
"prod"
]
}
}
then you need to use that condition at "Resources.Properties.Environment.Variables"
:
"Environment": {
"Variables": {
...,
"STRIPE_PK": {
"Fn::If": [
"IsProductionEnv",
"pk_live_...",
"pk_test_..."
]
}
}
}
I have "dev" and "prod" amplify env names. it will handle your deployments and manage your env variables based on env for that function.