Accessing Elastic Beanstalk Envionment Variables on the Command Line
Overview[edit]
Sometimes it is useful to have access to key/value pairs created in the EBS environment configuration, for example to insert them into commands that create security certificates. [1]
Location[edit]
The location on the file system where EBS stores environment variables registered through the configuration of the EBS environment: /opt/elasticbeanstalk/deployment/env
get-config platform script[edit]
The get-config platform script is installed in EBS environments and can be used to retrieve EBS environment variable values.
The script is located at /opt/elasticbeanstalk/bin/get-config.
Sample usage:
$ LETSENCRYPT_DOMAIN=$(/opt/elasticbeanstalk/bin/get-config environment -k LETSENCRYPT_DOMAIN)
$ echo ${LETSENCRYPT_DOMAIN}
Loading EBS key/value pairs (legacy)[edit]
The information in this section does not seem to work on Amazon Linux 2. The source command is problematic. This information is saved for archival purposes.
To access EBS environment variables on the command line:
$ source /opt/elasticbeanstalk/deployment/env
Actually, ec2-user doesn’t have permission to do that to that file. .ebextension config files seem to run as super user, so it should be fine within that context.
To get this functionality from the command line on a EBS server:
$ source <(sudo cat /etc/environment)
Notes[edit]
- ↑ How can I pass variables from my Elastic Beanstalk environment to Linux instances? - AWS Knowledge Center