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
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With