Keeping Elastic Beanstalk configs in code

I am a huge fan of Amazon Web Services, especially Elastic Beanstalk, and I love how easy it is to spin up and cast aside instances. When running Node services I use environment variables which conditionally load the specific configuration needed.

Now with several EC2 instances running, it can be tedious setting all those environment variables. To avoid this, and to keep all your custom configurations in your repo, I use the following;

I would not recommend you do this with security keys (S3/Facebook Tokens). I woudl definitely not do this if your source control is not suitably private and secure. So stop reading if you use public repositories as there are bots which scape GitHub etc for such values.

In your project root

  • Create a folder called .ebextensions
  • In that folder create a file called environment.config
  • Add the following code to the file
option_settings:<br />
  - option_name: <em>NODE_ENV</em>
    value: <em>production</em>

Once committed and deployed, the variables should appear in the ELB/EC2 configuration details.