使用Boto3更改S3存储桶中对象的ACL

Ram*_*amu 4 amazon-s3 bucket

试图找出一种使用Boto3在S3存储桶中的对象上设置ACL的方法。输入应为S3存储桶名称,并将所有对象的ACL更改为仅公共读取

ale*_*dnm 6

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'))
Run Code Online (Sandbox Code Playgroud)

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

bucket.Acl().put(ACL='public-read')
Run Code Online (Sandbox Code Playgroud)


Joh*_*ein 1

您可以copy_object()在设置 ACL 时将该对象设为自身。

因此,源将与目标相同,但将 ACL 设置为您所需的值。