简体   繁体   English

Amazon OpsWorks NodeJS环境变量

[英]Amazon OpsWorks NodeJS environment variables

I configured a stack for a NodeJS application server using Amazon OpsWorks. 我使用Amazon OpsWorks为NodeJS应用程序服务器配置了堆栈。

I need to access some environment variables which define Google API credentials. 我需要访问一些定义Google API凭据的环境变量。 How can I achieve this ? 我该如何实现? I already spent more two days on this. 我已经花了两天了。

I ended up by the following chef recipe : 我最后得到了以下厨师食谱:

magic_shell_environment "GOOGLE_CLIENT_ID" do
    owner 'root'
    group 'root'
    value "********"
    mode  '0600'
end

I use the root account because it seems the NodeJS is run under that account. 我使用root帐户,因为似乎NodeJS在该帐户下运行。 If I remove the owner and group attributes, I can read those environment variables fine (as the default ubuntu user). 如果删除ownergroup属性,则可以正常读取这些环境变量(作为默认的ubuntu用户)。 However, when I ssh to my instance and type echo $GOOGLE_CLIENT_ID as root, I get an empty string. 但是,当我对自己的实例执行SSH并以root身份键入echo $GOOGLE_CLIENT_ID ,我得到一个空字符串。

Also, where is logged the output of console.xxxx(...) ? 另外, console.xxxx(...)的输出记录在哪里?

OpsWorks now lets you specify up to 20 custom environment variables in the app settings page. 现在,OpsWorks可让您在“应用程序设置”页面中最多指定20个自定义环境变量。 In the case of a node.js app these will be available in the process.env object. 对于node.js应用程序,这些将在process.env对象中可用。 在此处输入图片说明

Use the OpsWorksEnvy cookbook. 使用OpsWorksEnvy食谱。 It hooks nicely into the default nodejs cookbooks and lets you set the environment variables in your stack attributes. 它很好地连接了默认的nodejs食谱,并允许您在堆栈属性中设置环境变量。

This should be fairly easy to do. 这应该很容易做到。 Just add the following line to the top of your recipe. 只需将以下行添加到食谱顶部即可。

ENV['GOOGLE_CLIENT_ID']="YOUR_CLIENT_ID"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM