[Fixed]-Where are my environment variables in Elastic Beanstalk for AL2?


Try running the command /opt/elasticbeanstalk/bin/get-config environment after you ssh into the EC2 instance.



During deployment, the environment properties are readily available to your .platform hook scripts.

After deployment, e.g. when using eb ssh, you need to load the environment properties manually.

One option is to use the EB get-config tool. The environment properties can be accessed either individually (using the -k option), or as a JSON or YAML object with key-value pairs.

For example, one way to export all environment properties would be:

export $(/opt/elasticbeanstalk/bin/get-config --output YAML environment | 
         sed -r 's/: /=/' | xargs)

Here the get-config part returns all environment properties as YAML, the sed part replaces the ': ' in the YAML output with '=', and the xargs part fixes quoted numbers.

Note this does not require sudo.

Alternatively, you could refer to this AWS knowledge center post:

Important: On Amazon Linux 2, all environment properties are centralized into a single file called /opt/elasticbeanstalk/deployment/env. You must use this file during Elastic Beanstalk’s application deployment process only. …

The post describes how to make a copy of the env file during deployment, using .platform hooks, and how to set permissions so you can access the file later.

You can also perform similar steps manually, using SSH. Once you have the copy set up, with the proper permissions, you can source it.


Note: Environment properties with spaces or special characters are interpreted by the Bash shell and can result in a different value.



If you are trying to access the environment variables in eb script elastic beanstalk
Use this

$(/opt/elasticbeanstalk/bin/get-config environment -k ENVURL)
{ "Ref" : "AWSEBEnvironmentName" }
    $(/opt/elasticbeanstalk/bin/get-config environment -k ENVURL)

Leave a comment