Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CarrierWave Fog Credentials, Access Denied

I am trying to use CarrierWave with Amazon S3. When I try to upload a file, through a rake task, I get this error:

rake aborted!
Expected(200) <=> Actual(403 Forbidden)

My CarrierWave initializer looks like this:

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',
    aws_access_key_id: MY_AWS_ACCESS_KEY_ID,
    aws_secret_access_key: MY_AWS_SECRET_ACCESS_KEY
  }
  config.fog_directory = MY_BUCKET
  config.fog_public = true
end

I do have real, hard-coded key/secret/bucket values set while I'm debugging this.

The rake task looks like this, and is successful when I have the CarrierWave uploader set to upload locally with storage: file:

Photo.create({
  image: File.new('lib/dummy_files/image.jpg')
})

Any help is much appreciated. Thanks!

like image 485
Tyler Avatar asked Jul 30 '13 02:07

Tyler


2 Answers

I realized this has to do with the new AWS Identity and Access Management (IAM). I had created a new IAM user, but I hadn't given that user the correct privileges. In the past, there was only one user, and that user had admin privileges. Now you have to create a user, give that user the correct privileges, and use that user's credentials. I hope this helps someone.

like image 199
Tyler Avatar answered Nov 05 '22 21:11

Tyler


This answer helped me too ... specifically, it's under IAM > Users > Permissions > Attach User Policy

When you first create a user it gets no 'user policies' under 'permissions.' Once I attached a user policy things worked.

like image 11
pocus Avatar answered Nov 05 '22 21:11

pocus