15

I've created a file called .elasticbeanstalk/environment.config with the following in it:

option_settings:
  - option_name: NODE_ENV
    value: development

I'm also passing the process.env.NODE_ENV to the view so I can check the value

app.get('/', function(req, res) {
  var data = {
    env: process.env.NODE_ENV
  }
  res.render('upload',data);
});

On my local machine I get the value "local" which is what I've set it to. When I deploy to Amazons Elastic Beanstalk via $ git aws.push the value is empty.

Is there anything else I need to do for EB to recognise the NODE_ENV setting?

Andy Jarrett
  • 863
  • 2
  • 9
  • 26

2 Answers2

30

Your .config file should be located in the .ebextensions directory, not .elasticbeanstalk.

Try it then, if that doesn't work, you can always use the console.

In the meantime, you can always use the Elastic Beanstalk Console which let's you add environment variables from its interface. To do so, just:

  1. Open up your environment.
  2. You'll see Dashboard, Configuration, Logs and more on the left. Click the Configuration link.
  3. Then click the gear icon next to the Software Configuration block.
  4. Scroll down and add a key/value for the Environment Properties.
Josh Davis
  • 6,651
  • 2
  • 25
  • 25
  • Awesome stuff - think I took in too much at the same time and wasn't properly reading the docs. – Andy Jarrett Oct 02 '14 at 21:39
  • I use the `Dockerrun.aws.json` to deploy the image that I built before. In this case, I can't access any of the env variables (both from UI and from .config) on the app. – Anand Oct 19 '21 at 10:36
8

Other ways to set environment variables in elastic beanstalk are -

  1. Create a config file in .ebextensions directory like environmentalvar.config and define variables in option_settings and include this file into application bundle. (Aws Documentation)

    example -

    option_settings:
         aws:elasticbeanstalk:application:environment:
           NODE_ENV: production
    
  2. By using elastic beanstalk command line tool. Command for set variable-

    eb setenv VAR_NAME=VAR_VALUE

Karan
  • 2,102
  • 2
  • 22
  • 31