找出我的Node.js应用程序当前正在运行的AWS Beanstalk环境的最佳实践是什么?

时间:2021-05-06 20:58:11

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

我的Node.js Express应用程序在AWS Beanstalk中运行。我为我的应用程序创建了三个Beanstalk环境,即:

  • DEV (Development)
  • UAT (User Acceptance Testing)
  • UAT(用户验收测试)

  • PROD (Production)

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?

找出我的Node.js应用程序当前正在运行的AWS Beanstalk环境的最佳实践是什么?

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.

我得到的印象是我应该使用Beanstalk环境标签,但我无法弄清楚如何通过我的Node.js应用程序访问它们。

1 个解决方案

#1


2  

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

这是正确的,使用您从Beanstalk控制台配置的环境变量,让应用程序的实例知道它正在运行的环境。您没有在节点beanstalk应用程序中获得那么多选项,但如果您只想要传递数据库连接字符串和css路径,您可以使用PARAM1和PARAM2,然后从您的应用程序中访问这些

process.env.PARAM1 & process.env.PARAM2

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).

你的另一个选择只是在PARAM1中传递一些软“env”变量,然后让你的应用程序解决你的各种配置(但这会在你的应用程序中添加另一个隐藏的配置层)。

#1


2  

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

这是正确的,使用您从Beanstalk控制台配置的环境变量,让应用程序的实例知道它正在运行的环境。您没有在节点beanstalk应用程序中获得那么多选项,但如果您只想要传递数据库连接字符串和css路径,您可以使用PARAM1和PARAM2,然后从您的应用程序中访问这些

process.env.PARAM1 & process.env.PARAM2

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).

你的另一个选择只是在PARAM1中传递一些软“env”变量,然后让你的应用程序解决你的各种配置(但这会在你的应用程序中添加另一个隐藏的配置层)。