0
votes

I am getting following errors on my Heroku logs:-

Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden) 2013-10-02T16:25:51.131316+00:00 app[web.1]: response => #"\nInvalidAccessKeyIdThe AWS Access Key Id you provided does not exist in our records.5CA6A058BCE5D28AQ6grl4LPNO+F9YVtJZA7YIASYUFw4IpggAVlMJEzsdAhdwSWOTIB8K+VolEwyGYLS3_KEY", :headers=>{"x-amz-request-id"=>"5CA6A058BCE5D28A", "x-amz-id-2"=>"Q6grl4LPNO+F9YVtJZA7YIASYUFw4IpggAVlMJEzsdAhdwSWOTIB8K+VolEwyGYL", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Wed, 02 Oct 2013 16:25:50 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, :status=>403, :remote_ip=>"176.32.100.200"}, @body="\nInvalidAccessKeyIdThe AWS Access Key Id you provided does not exist in our records.5CA6A058BCE5D28AQ6grl4LPNO+F9YVtJZA7YIASYUFw4IpggAVlMJEzsdAhdwSWOTIB8K+VolEwyGYL

I have checked the AWS key for at least a dozen times. I have set up Heroku variables by using following:

heroku config:add S3_KEY=XXXXXXXXXXXXXXX S3_SECRET=XXXXXXXXXXXXXXXXXXXXXX

But I get the error as above.

2

2 Answers

1
votes

Looks like your AWS access key is invalid. A couple things to double check:

  • Do your access key, secret key and bucket all match what's in the AWS dashboard?

  • Are you setting those variables correctly in your carrierwave initializer? You should be able to check by running the following from heroku run rails console: CarrierWave.configure { |config| puts config.fog_credentials; puts config.fog_directory }.

If you double and triple check those and there really isn't anything wrong, then you may have a weird problem with your S3 account (can you access your S3 account with another S3 utility using the same credentials?), or there's something loony happening in your code.

Good luck!

0
votes

I was able to figure out using Taavo's suggestion. I used figaro gem where I did put AWS credentials into config/application.yml.

In addition, I also changed my carrierwave.rb file from:

CarrierWave.configure do |config|

  config.fog_credentials = {
    provider: "AWS",
    aws_access_key_id: "S3_KEY",
    aws_secret_access_key: "S3_SECRET",

  }
  config.cache_dir = "#{Rails.root}/tmp/uploads" 
  config.fog_directory = "S3_BUCKET_NAME"
  config.fog_public = false
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end

to

CarrierWave.configure do |config|

  config.fog_credentials = {
    provider: "AWS",
    aws_access_key_id: ENV["S3_KEY"],
    aws_secret_access_key: ENV["S3_SECRET"],
    #region: 'Northern California'

  }
  config.cache_dir = "#{Rails.root}/tmp/uploads" 
  config.fog_directory = ENV["S3_BUCKET_NAME"]
  config.fog_public = false
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end

Then added following to Heroku:

$ heroku config:set S3_BUCKET_NAME=your_bucket_name
$ heroku config:set S3_KEY=your_access_key_id
$ heroku config:set S3_SECRET=your_secret_access_key

That did the work. Thanks Taavo for suggestions.