1.首先,需要安装AWS SDK for Python(Boto3)。
2.创建连接:
import boto3
s3 = boto3.resource('s3')
3.复制对象:
source_bucket = s3.Bucket("source-bucket-name")
dest_bucket = s3.Bucket("destination-bucket-name")
for obj in source_bucket.objects.all():
source_key = obj.key
dest_key = "new-prefix/" + source_key # 更改名称
copy_source = {
'Bucket': source_bucket.name,
'Key': source_key
}
dest_bucket.copy(copy_source, dest_key)
这个代码块将从源存储桶中复制每个对象,并将名称更改为“new-prefix/object-key”,并将其粘贴到目标存储桶中。
下一篇:AWSS3接入点的资源字段错误