简体   繁体   中英

Amazon OpsWorks NodeJS environment variables

I configured a stack for a NodeJS application server using Amazon OpsWorks.

I need to access some environment variables which define Google API credentials. 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. If I remove the owner and group attributes, I can read those environment variables fine (as the default ubuntu user). However, when I ssh to my instance and type echo $GOOGLE_CLIENT_ID as root, I get an empty string.

Also, where is logged the output of console.xxxx(...) ?

OpsWorks now lets you specify up to 20 custom environment variables in the app settings page. In the case of a node.js app these will be available in the process.env object. 在此处输入图片说明

Use the OpsWorksEnvy cookbook. It hooks nicely into the default nodejs cookbooks and lets you set the environment variables in your stack attributes.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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