I got this error Missing required arguments: aws_access_key_id, aws_secret_access_key
. That seems weird because I already added carrierwave.rb in initializers folder. The access/secret key works perfectly when I use aws-sdk
CarrierWave.configure do |config|
config.fog_credentials = {
provider: "AWS",
aws_access_key_id: ENV["PUB-KEY"],
aws_secret_access_key: ENV["SEC-KEY"]
}
config.fog_directory = ENV["mybucket"]
end
Here's what my working one looks like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:region => 'us-east-1'
}
config.fog_directory = ENV['S3_BUCKET']
end
For production, I added the keys S3_KEY
, S3_SECRET
and S3_BUCKET
. For development and testing, I used an initializer that is in a .gitignore
file:
# .gitignore
/config/initializers/app_environment_variables.rb
and in the initializer
# config/initializers/app_environment_variables.rb
ENV['S3_KEY'] = "********************"
ENV['S3_SECRET'] = "**************************..."
ENV['S3_BUCKET'] = "**********-dev"
Production and development configurations are different.
You need to put AWS keys in development too.
I just copied AWS keys from
config/environments/production.rb
to
config/environments/development.rb
And everything worked fine.