Python '的目的是什么;otherkey';在这个例子中。我不知道';我不明白为什么一个副本需要的不仅仅是源密钥

Python '的目的是什么;otherkey';在这个例子中。我不知道';我不明白为什么一个副本需要的不仅仅是源密钥,python,amazon-web-services,amazon-s3,boto3,Python,Amazon Web Services,Amazon S3,Boto3,我想使用boto3将文件从一个s3存储桶复制到另一个s3存储桶。我想不出应该用什么来代替“otherkey”。代码是否从copy_源中获取密钥并将其放入“otherbucket”中 导入boto3 s3=boto3.resource('s3') 复制源={ ‘Bucket’:‘mybucket’, 'Key':'mykey' } bucket=s3.bucket('otherbucket') obj=bucket.Object('otherkey') 对象复制(复制源) 我想出来了 import

我想使用boto3将文件从一个s3存储桶复制到另一个s3存储桶。我想不出应该用什么来代替“otherkey”。代码是否从copy_源中获取密钥并将其放入“otherbucket”中

导入boto3
s3=boto3.resource('s3')
复制源={
‘Bucket’:‘mybucket’,
'Key':'mykey'
}
bucket=s3.bucket('otherbucket')
obj=bucket.Object('otherkey')
对象复制(复制源)
我想出来了

import boto3
s3 = boto3.resource('s3')
copy_source = {
    'Bucket': 'bucket_from', #Name of bucket you want to copy FROM
    'Key': 'key' #file/object you want to copy
}
bucket = s3.Bucket('bucket_to') #name of bucket you want to copy TO
bucket.copy(copy_source, 'dump/new_file_name') # What you want the new copy to be named and where it should be placed
                                               #dump/ is the "subfolder", new_file_name is what the copied file is renamed to.

. 文档上说:Bucket(str)——复制到Key的Bucket的名称(str)——复制到
other*
的Key的名称就是目的地,不是很明显吗?我们建议您也提供示例参考的链接。与您发布的示例相比,这是不同的方法。