During the passage of Chapter 13, the Rails Tutorial encountered the inability to start downloading images on Heroku using CarrierWave, Fog and AWS S3. Every time I encounter the same error:
2019-04-22T16:45:52.736948+00:00 heroku[router]: at=info method=POST path="/microposts" host=anikeef-sample-app.herokuapp.com request_id=b78cf418-1931-42e0-89e5-4e92af697ed4 fwd="95.189.192.65" dyno=web.1 connect=0ms service=1525ms status=500 bytes=1891 protocol=https 2019-04-22T16:45:52.733710+00:00 app[web.1]: D, [2019-04-22T16:45:52.733568 #8] DEBUG -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] (2.3ms) ROLLBACK 2019-04-22T16:45:52.734152+00:00 app[web.1]: I, [2019-04-22T16:45:52.734037 #8] INFO -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] Completed 500 Internal Server Error in 511ms (ActiveRecord: 4.9ms) 2019-04-22T16:45:52.735688+00:00 app[web.1]: F, [2019-04-22T16:45:52.735602 #8] FATAL -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] 2019-04-22T16:45:52.735761+00:00 app[web.1]: F, [2019-04-22T16:45:52.735692 #8] FATAL -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] Excon::Error::Forbidden (Expected(200) <=> Actual(403 Forbidden) 2019-04-22T16:45:52.735764+00:00 app[web.1]: excon.error.response 2019-04-22T16:45:52.735769+00:00 app[web.1]: :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>1E231D51512F5FCD</RequestId><HostId>viioFqYRTbP07frHGpcfgl+xzN4cZqFMs37oY/dl0kHnzBNxpmoKNgjbQpxvG8kVCxaxFAxGFr0=</HostId></Error>" 2019-04-22T16:45:52.735770+00:00 app[web.1]: :cookies => [ 2019-04-22T16:45:52.735772+00:00 app[web.1]: ] 2019-04-22T16:45:52.735774+00:00 app[web.1]: :headers => { 2019-04-22T16:45:52.735776+00:00 app[web.1]: "Connection" => "close" 2019-04-22T16:45:52.735777+00:00 app[web.1]: "Content-Type" => "application/xml" 2019-04-22T16:45:52.735779+00:00 app[web.1]: "Date" => "Mon, 22 Apr 2019 16:45:51 GMT" 2019-04-22T16:45:52.735781+00:00 app[web.1]: "Server" => "AmazonS3" 2019-04-22T16:45:52.735783+00:00 app[web.1]: "x-amz-id-2" => "viioFqYRTbP07frHGpcfgl+xzN4cZqFMs37oY/dl0kHnzBNxpmoKNgjbQpxvG8kVCxaxFAxGFr0=" 2019-04-22T16:45:52.735784+00:00 app[web.1]: "x-amz-request-id" => "1E231D51512F5FCD" 2019-04-22T16:45:52.735786+00:00 app[web.1]: } 2019-04-22T16:45:52.735788+00:00 app[web.1]: :host => "anikeef-sample-app2.s3-us-east-2.amazonaws.com" 2019-04-22T16:45:52.735789+00:00 app[web.1]: :local_address => "172.17.49.150" 2019-04-22T16:45:52.735791+00:00 app[web.1]: :local_port => 43620 2019-04-22T16:45:52.735793+00:00 app[web.1]: :path => "/uploads/micropost/picture/304/sunrise-1756274_1920.jpg" 2019-04-22T16:45:52.735795+00:00 app[web.1]: :port => 443 2019-04-22T16:45:52.735796+00:00 app[web.1]: :reason_phrase => "Forbidden" 2019-04-22T16:45:52.735798+00:00 app[web.1]: :remote_ip => "52.219.104.80" 2019-04-22T16:45:52.735800+00:00 app[web.1]: :status => 403 2019-04-22T16:45:52.735801+00:00 app[web.1]: :status_line => "HTTP/1.1 403 Forbidden\r\n" 2019-04-22T16:45:52.735803+00:00 app[web.1]: ): 2019-04-22T16:45:52.735927+00:00 app[web.1]: F, [2019-04-22T16:45:52.735866 #8] FATAL -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] 2019-04-22T16:45:52.736039+00:00 app[web.1]: F, [2019-04-22T16:45:52.735966 #8] FATAL -- : [b78cf418-1931-42e0-89e5-4e92af697ed4] app/controllers/microposts_controller.rb:7:in `create'
So now it looks config / initializers / fog.rb
if Rails.env.production? CarrierWave.configure do |config| config.fog_provider = 'fog/aws' config.fog_credentials = { :provider => "AWS", :aws_access_key_id => ENV["S3_ACCESS_KEY"], :aws_secret_access_key => ENV["S3_SECRET_KEY"], :region => ENV["S3_REGION"] } config.storage = :fog config.fog_directory = ENV["S3_BUCKET"] config.cache_dir = "#{Rails.root}/tmp/uploads" end end
Judging by the error, the problem must come from AWS. I tried to apply different rights to IAM users, including AmazonS3FullAccess and AdministratorAccess. I reviewed all the issues found on the SO, but absolutely nothing helped me, so I will be very grateful for any help.