Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug AWS S3 "Access Denied"

I have a rails app with Paperclip hosted on Heroku (although I'm only testing locally right now)

I have created a bucket and a user with the AmazonS3FullAccess policy directly attached.

I have the following in development .rb

  config.paperclip_defaults = {
   storage: :s3,
   s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
   }
 }

However, when I try to attach a profile image to my model, I just get: Aws::S3::Errors::AccessDenied (Access Denied):

How can I go about debugging this problem? I have deleted and re-created both my IAM user and my bucket, but I cannot figure out where I'm going wrong.

Any insights into how to figure out what I'm missing?

like image 347
Joe Bauer Avatar asked Nov 06 '22 23:11

Joe Bauer


1 Answers

I didn't determine how to debug this issue, however, I did come to a solution.

First of all, I switched to gem 'aws-sdk-s3' instead of requiring the entire aws-sdk

I realized that I needed to create a policy for my bucket, specifically allowing my user full access. It seems that adding AmazonS3FullAccess to my user was not enough by itself.

I followed this guide step by step and it got me up and running.

like image 110
Joe Bauer Avatar answered Nov 12 '22 14:11

Joe Bauer