Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 Permission problem - How to set permissions for all files at once?

I have uploaded some files using the Amazon AWS management console.

I got an HTTP 403 Access denied error. I found out that I needed to set the permission to view.

How would I do that for all the files on the bucket?

I know that it is possible to set permission on each file, but it's time-consuming when having many files that need to be viewable for everyone.

like image 731
Rails beginner Avatar asked Sep 14 '11 17:09

Rails beginner


People also ask

What CLI command will list all of the S3 buckets you have access to?

Description. Returns a list of all buckets owned by the authenticated sender of the request. To use this operation, you must have the s3:ListAllMyBuckets permission. See 'aws help' for descriptions of global parameters.

How do I change permissions on S3 bucket?

To set ACL permissions for a bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to set permissions for. Choose Permissions. Under Access control list, choose Edit.

What is the by default permission given to Amazon S3 resources?

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.


2 Answers

I suggest that you apply a bucket policy1 to the bucket where you want to store public content. This way you don't have to set ACL for every object. Here is an example of a policy that will make all the files in the bucket mybucket public.

{     "Version": "2008-10-17",     "Id": "http better policy",     "Statement": [         {             "Sid": "readonly policy",             "Effect": "Allow",             "Principal": "*",             "Action": "s3:GetObject",             "Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*"         }     ] } 

That * in "Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*" allows recursion.


1 Note that a Bucket Policy is different than an IAM Policy. (For one you will get an error if you try to include Principal in an IAM Policy.) The Bucket Policy can be edit by going the root of the bucket in your AWS web console and expanding Properties > Permissions. Subdirectories of a bucket also have Properties > Permissions, but there is no option to Edit bucket policy

like image 177
cloudberryman Avatar answered Oct 15 '22 05:10

cloudberryman


You can select which directory you want it to be public.

Press on "more" and mark it as public; it will make the directory and all the files to be accessible as public.

like image 31
mohammad zein Avatar answered Oct 15 '22 06:10

mohammad zein