Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are items in my S3 bucket 403ing?

I am uploading documents via the AWS API to an S3 bucket. Works fine.

The items that are uploaded are marked as private though, so cannot be viewed online. I can get around this by right-clicking the file in the Console and clicking 'Make Public', or by using the API to make it public.

Is it possible to make all files uploaded public, so I don't have to make additional API calls to do so?

The following is a screenshot of the bucket's permissions:

enter image description here

I don't think it's anything to do with IAM, as the requesting user isn't a user at all, it's the public.

Thanks

like image 223
Mike Avatar asked Jan 15 '18 10:01

Mike


1 Answers

This can be done with a bucket policy (click bucket policy in your screenshot). e.g.,

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"AddPerm",
      "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::examplebucket/*"]
    }
  ]
}

(see "Granting Read-Only Permission to an Anonymous User" on https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html)

That allows anyone (*) to perform GetObject on any item in the bucket, rather than having to set the permissions per-item.

like image 119
Matt Avatar answered Nov 15 '22 05:11

Matt