user2616836
user2616836

Reputation:

Elastic Beanstalk custom AMI can't see environment variables

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?

Upvotes: 10

Views: 4257

Answers (3)

Sebastien Horin
Sebastien Horin

Reputation: 11069

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

export VARNAME="my value"

Check with:

printenv VARNAME

Upvotes: 0

Jon McAuliffe
Jon McAuliffe

Reputation: 3157

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.

Upvotes: 4

user2616836
user2616836

Reputation:

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

Upvotes: 14

Related Questions