Question:
I don’t know how (or where also) to grant read and write permission to the user from AWS so users can post pictures on sample_app in production enviroment. This is final task in 11th chapter, it isn’t covered by tutorial and I can’t find solution anywhere.
This is carrier_wave.rb
file:
1 2 3 4 5 6 7 8 9 10 11 12 |
if Rails.env.production? CarrierWave.configure do |config| config.fog_credentials = { # Configuration for Amazon S3 :provider => 'AWS', :aws_access_key_id => ENV['lalala'], :aws_secret_access_key => ENV['oloalle'] } config.fog_directory = ENV['name of bucket'] end end |
This is procedure from tutorial:
1) create AWS IAM User and record access and secret key – done
2) create S3 bucket – done
3) grant read and write permission to the user created in the previous step – how???
4) I then run this three commands:
1 2 3 4 |
$ heroku config:set S3_ACCESS_KEY=lalala $ heroku config:set S3_SECRET_KEY=oloalle $ heroku config:set S3_BUCKET=name of bucket |
5) push to git and heroku – done
6) heroku pg:reset DATABASE
– done
7)heroku run rake db:migrate
and here I get this message:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
Running `rake db:migrate` attached to terminal... up, run.7906 rake aborted! ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key /app/vendor/bundle/ruby/2.0.0/gems/fog-core-1.28.0/lib/fog/core/service.rb:244:in `validate_options' /app/vendor/bundle/ruby/2.0.0/gems/fog-core-1.28.0/lib/fog/core/service.rb:268:in `handle_settings' /app/vendor/bundle/ruby/2.0.0/gems/fog-core-1.28.0/lib/fog/core/service.rb:98:in `new' /app/vendor/bundle/ruby/2.0.0/gems/fog-core-1.28.0/lib/fog/storage.rb:25:in `new' /app/vendor/bundle/ruby/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog' /app/vendor/bundle/ruby/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials=' /app/config/initializers/carrier_wave.rb:3:in `block in /app/vendor/bundle/ruby/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure' /app/vendor/bundle/ruby/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure' /app/config/initializers/carrier_wave.rb:2:in ` /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:652:in `block in load_config_initializer' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:651:in `load_config_initializer' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:616:in `block (2 levels) in /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `each' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `block in /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `each' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `tsort_each_child' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!' /app/config/environment.rb:5:in ` /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!' /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace) |
Answer:
For others in future, this answer helped me a lot.
Go on Heroku, on your application, go to settings, hit Reveal Config Vars.
Click on on Edit on the right side and enter your secrets there:
1 2 3 4 |
S3_BUCKET: name of your bucket goes here S3_ACCESS_KEY: xxxxx S3_SECRET_KEY: xxxx |
On config/initializers/carrierwave.rb or wherever you’re entering your secrets should have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CarrierWave.configure do |config| config.root = Rails.root.join('tmp') # adding these... config.cache_dir = 'carrierwave' # ...two lines config.fog_credentials = { :provider => 'AWS', # required :s3_access_key_id => ENV['S3_ACCESS_KEY'], # required :s3_secret_access_key => ENV['S3_SECRET_KEY'], # required :region => 'eu-west-1', # optional, defaults to 'us-east-1' :host => 's3.example.com', # optional, defaults to nil :endpoint => 'https://s3.example.com:8080' # optional, defaults to nil } config.fog_directory = ENV['S3_Bucket'] # required config.fog_public = false # optional, defaults to true config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} end |