Search code examples
ruby-on-railsruby-on-rails-4amazon-web-servicesamazon-s3carrierwave

db:migrate gives ArgumentError: Missing required arguments: aws_secret_access_key


Every time I try to run db:migrate or heroku run console, I get ArgumentError: Missing required arguments: aws_secret_access_key

I have done heroku config:set for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Afterwards I run heroku config and see those two and theS3_BUCKETcorrect. Then I runheroku run console` and I get the error.

I have also went on my IAM management console and I gave my user the AmazonS3FullAccess policy. Although this does nothing.

I am also using config/application.yml from the figaro gem to store my keys, but that's no different either.

I'm out of ideas on what to do to fix this, does anyone know what to know?

carrierwave.rb:

if Rails.env.production?
    CarrierWave.configure do |config|
        config.root = Rails.root.join('tmp') # adding these...
        config.cache_dir = 'carrierwave' # ...two lines
        config.fog_credentials = {
            # Configuration for Amazon S3
            :provider => 'AWS',
            :aws_access_key_id => ENV['S3_ACCESS_KEY'],
            :aws_secret_access_key => ENV['S3_SECRET_KEY'],
            :region => 'us-west-2',
            :host => 's3.example.com',
            :endpoint => 'https://s3.example.com:8080'
        }
        config.fog_directory = ENV['S3_BUCKET']
        config.fog_public = false # optional, defaults to true
        config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  #   optional, defaults to {}
    end
end 

Solution

  • You have set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY but you application reads S3_ACCESS_KEY and S3_SECRET_KEY environment variables.