vim, git, aws and other three-letter words

Software Development Notes

Elastic Beanstalk: cron command and RDS DB access

Problem

We want to have a cron command that launches a PHP script with DB access.

The DB connection string looks like this:

'connectionString' => 'mysql:host='.$_SERVER['RDS_HOSTNAME'].';port='.$_SERVER['RDS_PORT'].';dbname='.$_SERVER['RDS_DB_NAME'],

where the RDS_xxx parameters come from environment variables.

The problem is that cron launches the command with a clean environment (there are no RDS_xxx variables). So the command fails to access the database.

Solution

The solution is to set the required environment variables before launching the command, and this can be done with the /opt/elasticbeanstalk/support/envvars script:

0 3 * * * . /opt/elasticbeanstalk/support/envvars; /var/www/html/console/yiic mycommand

Tags: aws