6

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.

ThomasReggi
  • 621
  • 2
  • 10
  • 25

3 Answers3

7

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.

ThomasReggi
  • 621
  • 2
  • 10
  • 25
3

Just Simple.

You should go to environment configurations of the current application being running over your elastic beanstalk.

First ssh into the elastic beanstalk instance like the above answer.

ssh eb

If you wanna show the environment variables related to RDS (like RDS_DB_NAME), then

cat /opt/python/current/env

You will also see some variables of aws:elasticbeanstalk:application:environment in option_settings together, typed before.

Additionally, if you want to apply that environment variables,

source /opt/python/current/env

And you can see those variables by scripting env

Manjun Gim
  • 31
  • 1
1

Here's my version that adds the vars to the current session

sudo /opt/elasticbeanstalk/bin/get-config environment --output yaml | sed -n '1!p' | sed -e 's/^\(.*\): /\1=/g' | sed -e 's/^/export /' > env.sh; source env.sh

It drops a temp file, but it works.