I am trying to get AWS setup so I can use that to store images for my rails app. The problem I am getting the following error when I try to push to Heroku:
ArgumentError: is not a recognized provider
Here is my carrierwave.rb code:
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_ACCESS_KEY'],
:aws_secret_access_key => ENV['S3_SECRET_KEY']
}
config.fog_credentials = ['S3_BUCKET']
end
end
Here is code from picture_uploader.rb file
if Rails.env.production?
storage :fog
else
storage :file
end
And finally this is my heroku config
DATABASE_URL: postgres://<url>
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: enabled
S3_ACCESS_KEY: <access_key>
S3_BUCKET: <bucket_name>
S3_SECRET_KEY: <secret_key>
SECRET_KEY_BASE: <key>
I'm missing something, but I just can't find it.
As soon as I posted this I saw the problem. Typo in the carrierwave.rb file.
Related
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"
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
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
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.
I've set heroku config vars with AWS credentials using:
heroku config:set S3_ACCESS_KEY=<....>
heroku config:set S3_SECRET_KEY=<....>
heroku config:set S3_BUCKET=<....>
and verified them on heroku:
heroku run rails console
CarrierWave.configure do |config|
puts config.fog_directory
puts config.fog_credentials
end
On my config/initializers/carrier_wave.rb file, I've got:
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_ACCESS_KEY'],
:aws_secret_access_key => ENV['S3_SECRET_KEY']
}
config.fog_directory = ENV['S3_BUCKET']
end
end
On app/uploaders/picture_uploader.rb file I've got:
if Rails.env.production?
storage :fog
else
storage :file
end
When deploying the app on heroku everything seems to be ok but trying upload a file leads to an Application Error page... Does this have to do with AWS rather than my code?
I have deployed my app on Ninefold, but it crashes when I try uploading pictures. The logs suggest that I'm missing my AWS credentials:
ArgumentError (Missing required arguments: aws_access_key_id, aws_secret_access_key)
But I'm fairly sure I've got them set up correctly using Fog and my .env file. CarrierWave initializer looks like this at the moment:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['S3_KEY'], # required
:aws_secret_access_key => ENV['S3_SECRET'], # required
:region => 'us-east-1' # optional, defaults to 'us-east1'
}
config.fog_directory = ENV['S3_BUCKET'], # required
end
Any suggestions on how to get this working correctly? Don't know what other info to give but if you need more info to help me solve let me know.
Have you set the environment variables in your app?
You need to add some variables with the relevant names in the Environment Variables section under the app deploy.
S3_KEY
S3_SECRET
S3_BUCKET
You amazon account should have the relevant details.