Clyde Brown
Clyde Brown

Reputation: 217

When I rake db:migrate, an ArgumentError appears

I want to start my project over from a remote commit so, after downloading the zipfile and puting back all of the .gitignore files, I recieve this error when I try to rake db:migrate.

ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
2.1.5/gems/fog-core-1.25.0/lib/fog/core/service.rb:234:in `validate_options'
2.1.5/gems/fog-core-1.25.0/lib/fog/core/service.rb:258:in `handle_settings'
/s/ruby-2.1.5/gems/fog-core-1.25.0/lib/fog/core/service.rb:98:in `new'
/gems/fog-core-1.25.0/lib/fog/storage.rb:25:in `new'
gems/carrierwave-carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
//.rvm/gems/ruby-2.1.5/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in     `fog_credentials='
/bloccit/config/initializers/fog.rb:2:in `block in <top (required)>'
e/.rvm/gems/ruby-2.1.5/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'

So, I know there's something wrong with my fog.rb file, but how do I fix it? And where is a good place to put the values for AWS codes?

My fog.rb

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.fog_directory   = ENV['AWS_BUCKET']
config.fog_public      = true
end

Upvotes: 0

Views: 1007

Answers (2)

Nitin
Nitin

Reputation: 7366

By below two ways you can get rid of this error. Error is because you are not having Environmental variable available in your system.

If you have ENV['AWS_ACCESS_KEY_ID'] and other environmental variables then pass them as string in for.rb.

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:               'AWS',
    aws_access_key_id:      'xxxxxxxx',
    aws_secret_access_key:  'xxxxxxxxxxx'
  }
  config.fog_directory   = 'xxxxxxx'
  config.fog_public      = true
end

If you don't have credential Or You don't want to use AWS space in development mode then you can use file system to save images.

change storage :fog to storage :file in your uploader file under app/uploaders. No other changes required.

Upvotes: 0

SHS
SHS

Reputation: 7744

you could put the values inside a yml file within config, separating sections by environment - like it's done in config/database.yml. you'll need to load the file of course, when the app starts. and it would be advisable to not commit this file.

alternatively, you could create a .env file in your app. check out https://github.com/bkeepers/dotenv

for a quick fix, you could send the values as environment variables with your rake task.

AWS_ACCESS_KEY_ID=123 AWS_SECRET_ACCESS_KEY=abc rake db:migrate

Upvotes: 3

Related Questions