Search code examples
ruby-on-railsamazon-web-servicesamazon-s3carrierwavefog

All Access to this object has been disabled when using carrierwave/fog to upload to aws s3


I'm getting this error when I try to upload to s3. I checked to make sure my aws credentials were correct. Here's the error that i'm getting.

```

Excon::Errors:`:Forbidden: Expected(200) <=> Actual(403 Forbidden)
excon.error.response
  :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AllAccessDisabled</Code><Message>All access to this object has been disabled</Message><RequestId></RequestId><HostId></HostId></Error>"
  :cookies       => [
  ]
  :headers       => {
    "Connection"       => "close"
    "Content-Type"     => "application/xml"
    "Date"             => "Fri, 13 May 2016 22:14:48 GMT"
    "Server"           => "AmazonS3"
    "x-amz-id-2"       => ""
    "x-amz-request-id" => ""
  }
  :host          => "s3.amazonaws.com"
  :local_address => "10.0.0.24"
  :local_port    => 57133
  :path          => "/uploads/script/file/1/Facebook-2006.jpg"
  :port          => 443
  :reason_phrase => "Forbidden"
  :remote_ip     => "54.231.114.148"
  :status        => 403
  :status_line   => "HTTP/1.1 403 Forbidden\r\n"

```

And this is how I configured carrierwave/fog config/initializer/carrierwave.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"] } config.fog_directory = ENV["AWS_S3_BUCKET"] end


Solution

  • Idiot move. I was setting the name of the bucket name wrong. I wrote ENV["AWS_S3_BUCKET"] instead of ENV['S3_BUCKET_NAME']. It was saying access denied probably because it was trying to access a bucket that doesn't exist or is the root of s3.