S3 Boto3 python - 将所有文件acl更改为public read

我试图将S3存储文件夹中的500k文件的ACL从“私有”更改为“公共读取”

Is there any way to speed this up?

我使用下面的代码片段 .

from boto3.session import Session
from multiprocessing.pool import ThreadPool
pool = ThreadPool(processes=100)

BUCKET_NAME = ""
aws_access_key_id = ""
aws_secret_access_key = ""
Prefix='pics/'

session = Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
_s3 = session.resource("s3")
_bucket = _s3.Bucket(BUCKET_NAME)

def upload(eachObject):
    eachObject.Acl().put(ACL='public-read')

counter = 0
filenames = []
for eachObject in _bucket.objects.filter(Prefix=Prefix):
    counter += 1
    filenames.append(eachObject)
    if counter % 100 == 0:
        pool.map(upload, filenames)
        print(counter)
if filenames:
    pool.map(upload, filenames)

回答(0)