Sabyasachi Ghosh
Sabyasachi Ghosh

Reputation: 2785

Aws::S3::Errors::AccessDenied: Access Denied

I am trying to upload files to S3 using Aws-S3 gem.

s3 = Aws::S3::Resource.new(
 credentials: Aws::Credentials.new('XXX', 'XXX'),  
region: 'us-east-1') 

obj = s3.bucket('bucket-name').object('key')

obj.upload_file('/Users/saghosh/Downloads/projecttimeline_Dec 2017_MajorprojectN.pdf',acl:'public-read')

But every time it's giving me Aws::S3::Errors::AccessDenied: Access Denied.

But if I am trying to give

s32 = Aws::S3::Client.new(
  access_key_id: 'XXX',
  secret_access_key: 'XXX',
  region: 'us-east-1'
)
 s32.list_objects({bucket: 'bucket-name'})

it's working fine and listing all my manually uploaded file. It seems like a permission issue but not able to figure it out where the problem is?

Upvotes: 1

Views: 4055

Answers (2)

saqib
saqib

Reputation: 107

you get this error due to account permission try

    :s3_permissions => 'public-read'
:s3_permissions => 'private'


 config.paperclip_defaults = {
   :storage => :s3,
   :s3_permissions => 'public-read',
   :s3_credentials => {
    :bucket => "",
    :access_key_id => "",
    :secret_access_key => "",
    :s3_region => "us-east-1"
  }
}

Upvotes: 0

Ravi Rayapati
Ravi Rayapati

Reputation: 21

It could be a problem with IAM policy attached to the access/secret keys you were using. Make sure the appropriate S3 permissions are granted in order to perform actions via SDK.

Upvotes: 1

Related Questions