0
votes

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

3
Is this a first-run? Environment variables aren't set until the second run - sethvargo
Do you mean that I have to restart the instance once after the configure step? - Juljan
No - I mean during the first Chef run, the env variables aren't loaded yet - sethvargo

3 Answers

1
votes

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. enter image description here

0
votes

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"
0
votes

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