Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not recognizning ENV variables in S3.yml in rails

I'm currently trying to configure Paperclip with newest aws-sdk suggested gem.

On my S3.yml file I have something like this

development:
  bucket: newmeeter-dev
  access_key_id: ENV['S3_KEY']
  secret_access_key: ENV['S3_SECRET']

But it is not recognizing the ENV variables. I'm getting the following error

AWS::S3::Errors::InvalidAccessKeyId in PhotosController#create

The AWS Access Key Id you provided does not exist in our records.

If I try to put both the access and secret directly into the file it works perfectly. At the same time I tried to print both ENV variables into the views or in the console I can see their values okay.

I'm not getting why it is not recognizing it.

like image 544
Martin Avatar asked Apr 28 '12 18:04

Martin


1 Answers

Solved!

I found the reply to this question here Ruby on Rails: Can you put Ruby code in a YAML config file?

Solution: YAML files understand code in ERB format.

Printing ENV variables inside <%= and %> works.

access_key_id: <%= ENV['S3_KEY'] %>
secret_access_key: <%= ENV['S3_SECRET'] %>
like image 188
Martin Avatar answered Sep 19 '22 08:09

Martin