Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk connect to RDS from shell SSH

I have a python application on an Elastic Beanstalk EC2 instance which is connected to an PostgreSQL RDS.

My application works fine and uses the environment variables that are set by Elastic Beanstalk to connect with the database:

os.environ['RDS_DB_NAME']
os.environ['RDS_USERNAME']
os.environ['RDS_PASSWORD']
os.environ['RDS_HOSTNAME']
os.environ['RDS_PORT']

However, this doesn't work when I login on the EC2 instance with SSH. The RDS environment variables are not set. Since my application works in the browser, I think it cannot be the security groups. I've also tried to access the variables with the virtualenv activated.

How can I make elastic beanstalk to define these variables when I have an SSH connection?

like image 804
JacobF Avatar asked Jan 21 '14 10:01

JacobF


2 Answers

I did not find the scripts you have mentionned but find another way to reach the same information.

cd /opt/elasticbeanstalk/bin
sudo ./get-config environment

Get config script allow you to get access to a lot of indormaftion on this categories :

optionsettings                   environment option settings that affect instance
container                        container specific configurations
addons                           addon configurations
environment                      environment variables
meta                             EB environment meta-data

Hope it helps.

like image 144
wascou Avatar answered Sep 28 '22 19:09

wascou


I figured it out this morgning:

The environment variables are not set within the virtualenv, but by another script. First you have to activate the virualenv, then you need to load the variables by activating the env script in the 'current' directory. Like this:

source /opt/python/run/venv/bin/activate
source /opt/python/current/env

The Beanstalk RDS variables are now set and ready to use by any script you execute in SSH.

like image 31
JacobF Avatar answered Sep 28 '22 19:09

JacobF