How to view the RDS_ prefixed environment variables in AWS ElasticBeanstalk

amazon-ebsamazon-rdsenvironment-variables

If you set up RDS with ElasticBeanstalk how can you go into the box (via eb ssh) and view the environment variables that are set when you apply RDS to your EB Instance?

Amazon automatically sets up these environment variables.

  • RDS_DB_NAME
  • RDS_USERNAME
  • RDS_PASSWORD
  • RDS_HOSTNAME
  • RDS_PORT

It seems that you can only view in the process that runs your application.

I'd like to view these via the terminal some way, the eb printenv command does not show them.

Best Answer

Here's how to do it.

First ssh into the eb instance.

eb ssh

Then un the following command

sudo /opt/elasticbeanstalk/bin/get-config environment --output YAML

Alternatively --output YAML can be --output json.

Or if you want you can pipe the variables into a node command like this:

#!/usr/bin/env node
var strings = []
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(data) {
  var json = JSON.parse(data)
  for (var key in json) {
    var val = json[key]
    strings.push(key + '="' + val + '"')
  }
})
process.stdin.on('end', function() {
  var output = strings.join('\n')
  process.stdout.write(output)
})

And use source to have .ebextension scripts get access to the env variables.