When I rake db:migrate, an ArgumentError appears - ruby-on-rails

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

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

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.

Related

in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)

Everything has been great. Until I checked out a new branch, and now I get this error. I use figaro which generated an application.yml to store the env variables for the aws credentials. I have successfully been able to deploy to heroku and use my aws keys to upload pics, etc. to my bucket. Then I checkout a new branch and this error. I even went back to the old branch where everything was just peachy and this error won't go away. I'm frustrated. I even go into the terminal and do echo $aws_access_key_id and I don't get nil, I get the access key. Something doesn't add up...
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'],
region: 'us-east-1'
}
config.fog_directory = ENV['AWS_BUCKET']
if Rails.env.development? || Rails.env.test?
CarrierWave.configure do |config|
config.storage = :file
end
end
# Use AWS storage if in production
if Rails.env.production?
CarrierWave.configure do |config|
config.storage = :fog
end
end
end
application.yml
aws_access_key_id: "key"
aws_secret_access_key: "key"

Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError) bin/rake assets:precompile RAILS_ENV=production

When I run:
$ bin/rake assets:precompile RAILS_ENV=production
I get this error:
gems/fog-core-2.1.0/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
This is my config/initializers/carrierwave.rb:
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_KEY'],
region: 'ca-central-1'
}
config.fog_directory = ENV['AWS_STORAGE']
config.fog_public = false
config.fog_attributes = { cache_control: "public, max-age=#
{365.days.to_i}" }
end
I am using:
gem 'dotenv-rails', groups: [:development, :test]
to manage my environment variable.
Please help.
As per the specifications shared it seems like dot-env is working only for development and test environment but not for production.
Secondly, you need to set the environment variables ACCESS_KEY_ID and AWS_KEY so that they are available in Rails.
You can do this in the terminal:
export ACCESS_KEY_ID=<your access key id>
export AWS_KEY=<your secret key>
Add those to your .bashrc or .bash_profile so they persist next time you start a new shell or use something like dotenv to make them specific to your project.
Another way could be setting their values in secrets.yml or .env file

Fail to deploy in heroku when using carrier wave and S3

I am a newbie in rails.
Right now using a tutorial for ruby and rails. In one of the section we using carrier wave and AWS S3 for photo storage.
when i deploy in heroku, there is an errors like this :
"ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key"
i write on the carrir_wave.rb as follow:
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['******************'],
:aws_secret_access_key => ENV['*************************']
}
config.fog_directory = ENV['*******************']
end
end
when I am running my test in terminal, all test was good.
I had been setting the credential on heroku through:
$ heroku config:set S3_ACCESS_KEY=<access key>
$ heroku config:set S3_SECRET_KEY=<secret key>
$ heroku config:set S3_BUCKET=<bucket name>
I am really appreciate with any one help.
Create some carrierwave.rb filr in config/initializers folder and place following code snippet in carrierwave.rb file
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], # required
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] # required
}
config.fog_directory = ENV['S3_BUCKET_NAME'] # required
end
and place your values for following keys in some .env file in project folder
1) AWS_ACCESS_KEY_ID
2) AWS_SECRET_ACCESS_KEY
3) S3_BUCKET_NAME
Then re-run your server from terminal

Figaro Gem Config Issues

I'm trying to setup Figaro in Rails 4, but after setting up the correctly yaml as such
application.yml
aws_access_key_id:'#'
aws_secret_access_key:'#'
fog_directory:'#'
CarrierWave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
provider: "AWS", # required
aws_access_key_id: ENV["aws_access_key_id"], # required
aws_secret_access_key: ENV["aws_secret_access_key"], # required
}
config.fog_directory = ENV["fog_directory"] # required
end
I keep getting this error
`global_configuration': undefined method `reject' for #<String:0x007f9c7a0d9a80> (NoMethodError)
I've looked into similar problems but haven't found the right answer, the YAML worked on http://www.yamllint.com/
The yaml file is super sensitive and even though it passed on http://www.yamllint.com/, there was a formatting error it didn't catch

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...
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.
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.

Resources