9

I'm using a custom AMI for Elastic Beanstalk because of some large package requirements.

When I SSH into the EC2 instance none of my environment variables (specified in the Elastic Beanstalk web console settings) are available to my app.

My app in production can access the variables just fine, but I cannot do so in the console, which is really making debugging anything very difficult.

How do I make all of the environment variables available when I'm using the SSH console?

3 Answers3

13

Found an easy way to load all the environment variables while perusing the Elastic Beanstalk support forums:

. /opt/python/current/env

To view a variable: echo ${VAR_NAME} or printenv VAR_NAME, which doesn't work before using the above command. (UNIX, get environment variable)

Bonus:

To simply view a list of the variables: printenv

To list the variables as exports: cat /opt/python/current/env

To add the exports to the end of a config file: cat /opt/python/current/env >> /path/to/my/file

Community
  • 1
  • 1
  • `/opt/python/current/env` doesn't exist in latest Amazon OS – YWCA Hello Nov 12 '14 at 20:39
  • 5
    I've found these environment variables stored in JSON under /opt/elasticbeanstalk/deploy/configuration/containerconfiguration. Edit: actually they're also in a regular environment variable listing under /var/elasticbeanstalk/staging/elasticbeanstalk.env – Joe Lee-Moyet May 26 '16 at 12:43
  • @YWCAHello that is not completely right, or at least it exists when I connect to my elastic beanstalk instances. – Mattia Paterna Aug 15 '17 at 07:24
  • 1
    In Amazon Linux 2, I found it at `/opt/elasticbeanstalk/deployment/env` – Mathew Dominic Sep 30 '20 at 17:12
4

The environment variables used by Elastic Beanstalk aren't shell environment variables. They're passed in to your application environment on launch (with different methods used for different languages).

E.g.

Java Environment Variables

PHP Environment Variables

I've solved this one in the past by having a page on the admin side of the app that just lists them for debugging purposes.

robd
  • 9,025
  • 5
  • 35
  • 53
Jon McAuliffe
  • 3,056
  • 1
  • 17
  • 9
0

For Node.js I had to manually add them with:

export VARNAME="my value"

Check with:

printenv VARNAME
Sebastien Horin
  • 8,814
  • 4
  • 39
  • 51