noetix
noetix

Reputation: 4923

Why I’m getting an `AccessDenied` when trying to upload to my S3 bucket with `PutObject` permissions?

Any idea why I’m getting an AccessDenied error when trying to upload to my S3 bucket?

serverless.yml:

service: foo-service

custom:
  bucket: my-bucket-name

provider:
  name: aws
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
      Resource: "arn:aws:s3:::${self:custom.bucket}/*"

functions:
  hello:
    handler: handler.hello
    environment:
      BUCKET: ${self:custom.bucket}

I'm trying to add a file to S3 with public-read permissions.

Upvotes: 1

Views: 213

Answers (1)

noetix
noetix

Reputation: 4923

The s3:PutObject permission alone allows you to add an item to the S3 bucket, but if you configure any ACL attributes you'll need the additional permission s3:PutObjectAcl.

It should be like this:

provider:
  name: aws
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
        - s3:PutObjectAcl
      Resource: "arn:aws:s3:::${self:custom.bucket}/*"

Upvotes: 1

Related Questions