Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing ACLs of objects in an S3 bucket using Boto3

Trying to figure out a way to set ACLs on objects in an S3 bucket using Boto3. Input should be the S3 bucket name and change the ACLs for all the objects to read only by public

like image 921
Ramu Avatar asked Oct 17 '17 22:10

Ramu


2 Answers

You can copy_object() the object to itself, while setting the ACL.

So, the source will be the same as the destination, but set the ACL to your desired value.

like image 20
John Rotenstein Avatar answered Sep 20 '22 12:09

John Rotenstein


From the boto3 docs

To change the ACL of a single object, first get the Object instance and then change the ACL. This next example does both:

(boto3
 .session
 .Session(region_name=<region_name>)
 .resource('s3')
 .Object(<bucket_name>, <key>)
 .Acl()
 .put(ACL='public-read'))

To change the ACL of a bucket, assuming you already have the bucket instance:

bucket.Acl().put(ACL='public-read')
like image 53
alejandrodnm Avatar answered Sep 22 '22 12:09

alejandrodnm