Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set environment variables with AWS Opsworks

I'm using AWS Opsworks to host my Rails App (Ruby 2.0/Rails 3.2). For assets compilation process, I am using AssetSync to upload the compiled assets automatically on S3. I used to store the credentials as environment variables.

Do you have any idea how can I do this with Chef/Opsworks?

Thanks.

like image 943
Erem Avatar asked Jan 21 '26 03:01

Erem


2 Answers

I know this is an older post, but I'm posting this in case this helps someone else.

I found the easiest way actually was to use one of Chef's deploy hooks (http://docs.opscode.com/resource_deploy.html#deploy-phases).

Add a directory called 'deploy' at the Rails project root.

In it add a file called before_restart.rb, with the code:

Chef::Log.info("Running deploy/before_restart.rb")

# map the environment_variables node to ENV
node[:deploy].each do |application, deploy|
  deploy[:environment_variables].each do |key, value|
    Chef::Log.info("Setting ENV[#{key}] to #{value}")
    ENV[key] = value
  end
end

When you trigger the OpsWorks deploy, you should be able to see the ENV vars being set in the Rails App Server instance log.

like image 177
btsai Avatar answered Jan 23 '26 21:01

btsai


I ended up using https://github.com/joeyAghion/opsworks_custom_env. It works pretty well.

like image 21
Erem Avatar answered Jan 23 '26 20:01

Erem