complete_morons
complete_morons

Reputation: 843

Missing required arguments: aws_access_key_id, aws_secret_access_key

I'm using carriervawe and fog with S3 bucket. I get the error in the title in development (when I run rails s or rake db:migrate) with the following code:

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: "AWS",
    aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
  }
  config.asset_host = "http://xxx.cloudfront.net"
  config.fog_directory = 'xxx'
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
  config.storage = :fog
end

I've also tried using (as suggested here)

<%= ENV['AWS_ACCESS_KEY_ID'] %>

but I get this error:

syntax error, unexpected '<' (SyntaxError)

My variables are in application.yml file

AWS_ACCESS_KEY_ID:  AKIAIxxx...
AWS_SECRET_ACCESS_KEY:  1xxx...

Upvotes: 3

Views: 6443

Answers (2)

Mag
Mag

Reputation: 71

If this is from the Michael Hartl tutorial, I solved my issues by renaming the initializer to carrierwave.rb instead of carrier_wave.rb, as suggested in the tutorial. I then re-ran the git and Heroku commands and it worked on the Heroku production server.

Upvotes: 0

Joel Brewer
Joel Brewer

Reputation: 1652

Not sure why, but for some reason your environment variables are likely being evaluated to nil. I like to use the figaro gem to manage my environment variables.

Simply add

gem "figaro"

to your gemfile.

Then run

figaro install

which will create an application.yml file and add it to your .gitignore (very important for security reasons). After this, you should be able to add your AWS keys to application.yml and access them in your carrierwave config like your currently have.

Upvotes: 4

Related Questions