I am using Elastic Beanstalk's aws:elasticbeanstalk:application:environment
namespace to configure my environment with env vars. How can I set different values for different environments (e.g. development versus production)?
option_settings:
aws:elasticbeanstalk:application:environment:
REDIS_HOST: localhost
option_settings:
aws:elasticbeanstalk:application:environment:
REDIS_HOST: prod.redis.server.com
Elastic Beanstalk lets you enter the environment variables for each environment using the management panel. On AWS, open Elastic Beanstalk. Go to your Application > Environment > Configuration > Software Configuration . Under Environment Properties you will find a list of properties you can configure.
To change your environment's capacityOpen the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list.
Environment properties are written to the /opt/python/current/env file, which is sourced into the virtualenv stack where the application runs. For more information, see Using the Elastic Beanstalk Python platform.
Elastic Beanstalk isn't great if you need a lot of environment variables. The simple reason is that Elastic Beanstalk has a hard limit of 4KB to store all key-value pairs. The environment had accumulated 74 environment variables — a few of them had exceedingly verbose names.
The AWS CLI has a convenient way of doing this for you as the update-environment
command allows you to set env vars from a specially formatted json file. Create a separate json file for each environment you will be deploying to.
Example json file named deploy-dev.json
:
[
{
"Namespace": "aws:elasticbeanstalk:application:environment",
"OptionName": "NODE_ENV",
"Value": "dev"
},
{
"Namespace": "aws:elasticbeanstalk:application:environment",
"OptionName": "LOG_LEVEL",
"Value": "silly"
}
]
Deploy app and then update env vars:
aws elasticbeanstalk create-application-version --application-name "$EB_APP_NAME" --version-label "$EB_VERSION"
aws elasticbeanstalk update-environment --environment-name "$EB_ENV_NAME" --version-label "$EB_VERSION" --option-settings file://.ebextensions/deploy-dev.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With