Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make uploaded files to S3 public by default

I have tried a bunch of suggested solutions from Stack Overflow and other sites, but to no avail.

I have a bucket which I am uploading files to from a web page using one of the IAM accounts that I have created. These uploaded files are located within dynamically created folders within my parent bucket.

I need to ensure that any folder which is created along with any uploaded files held within the newly created folder are all public so any user can see them and download them.

Currently I am using the "S3 browser" application however it is not allowing me to download any of the uploaded files (although I can actually see them).

Any help is greatly appreciated!

like image 768
John Dunlea Avatar asked Jan 13 '15 05:01

John Dunlea


People also ask

How are objects uploaded to S3 by default?

When you upload a folder, Amazon S3 uploads all of the files and subfolders from the specified folder to your bucket. It then assigns an object key name that is a combination of the uploaded file name and the folder name.

Are S3 bucket public by default?

By default, new buckets, access points, and objects don't allow public access. However, users can modify bucket policies, access point policies, or object permissions to allow public access. S3 Block Public Access settings override these policies and permissions so that you can limit public access to these resources.

What is the default setting for S3 storage visibility?

By default, all Amazon S3 buckets and objects are private. Only the resource owner which is the AWS account that created the bucket can access that bucket. The resource owner can, however, choose to grant access permissions to other resources and users.


1 Answers

Create a Bucket Policy on that specific bucket, which grants GetObject permissions for anonymous users. Replace "examplebucket" with the name of the bucket. You can add the Bucket Policy in the Amazon S3 Management Console, in the Permissions section.

{
  "Version":"2012-10-17",
  "Statement":[{
    "Sid":"AddPerm",
        "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::examplebucket/*"
      ]
    }
  ]
}
like image 194
John Rotenstein Avatar answered Sep 30 '22 17:09

John Rotenstein