在elasticbeanstalk中设置NODE_ENV变量

时间:2022-11-26 23:02:32

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

我创建了一个名为.elasticbeanstalk / environment.config的文件,其中包含以下内容:

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

我也将process.env.NODE_ENV传递给视图,以便我可以检查值

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.

在我的本地机器上,我得到的值是“本地”,这是我设置的。当我通过$ git aws.push部署到Amazons Elastic Beanstalk时,该值为空。

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

我还需要做什么让EB识别NODE_ENV设置吗?

1 个解决方案

#1


13  

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

您的.config文件应位于.ebextensions目录中,而不是.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:

在此期间,您始终可以使用Elastic Beanstalk控制台,您可以从其界面添加环境变量。为此,只需:

  1. Open up your environment.
  2. 打开你的环境。

  3. You'll see Dashboard, Configuration, Logs and more on the left. Click the Configuration link.
  4. 您将在左侧看到仪表板,配置,日志等。单击“配置”链接。

  5. Then click the gear icon next to the Software Configuration block.
  6. 然后单击“软件配置”块旁边的齿轮图标。

  7. Scroll down and add a key/value for the Environment Properties.
  8. 向下滚动并为“环境属性”添加键/值。

#1


13  

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

您的.config文件应位于.ebextensions目录中,而不是.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:

在此期间,您始终可以使用Elastic Beanstalk控制台,您可以从其界面添加环境变量。为此,只需:

  1. Open up your environment.
  2. 打开你的环境。

  3. You'll see Dashboard, Configuration, Logs and more on the left. Click the Configuration link.
  4. 您将在左侧看到仪表板,配置,日志等。单击“配置”链接。

  5. Then click the gear icon next to the Software Configuration block.
  6. 然后单击“软件配置”块旁边的齿轮图标。

  7. Scroll down and add a key/value for the Environment Properties.
  8. 向下滚动并为“环境属性”添加键/值。