Frank
Frank

Reputation: 620

What is the best practice for figuring out in which AWS Beanstalk Environment my Node.js application is currently running?

My Node.js Express application runs in AWS Beanstalk. I've created three Beanstalk Environments for my application, namely:

Dependent upon the environment my application is running in I would like to connect to different databases and use different cascading style sheets.

What is the best practice for figuring out in which AWS Beanstalk Environment my Node.js application is currently running?

I get the impression I should be using Beanstalk Environment Tags, but I've not been able to figure out how to access them via my Node.js application.

Upvotes: 2

Views: 182

Answers (1)

Jon McAuliffe
Jon McAuliffe

Reputation: 3157

That's correct, use the environment variables you have configured from the Beanstalk console to let the instance of the application know which environment it is running in. You don't get that many options in a node beanstalk app, but if you say only want to pass a db connection string and a css path, you could do that with PARAM1 and PARAM2, then access these from within your app with

process.env.PARAM1 & process.env.PARAM2

(I've usually pushed these in to more appropriate names/places on application bootstrap).

Your other option is just to pass in some soft of 'env' variable in PARAM1, then have your app work out what to do with your various configurations (but this adds another hidden layer of config into your application).

Upvotes: 2

Related Questions