Amazon web services 递归地将s3对象从一个前缀复制到另一个前缀
我正在尝试将所有内容从Amazon web services 递归地将s3对象从一个前缀复制到另一个前缀,amazon-web-services,amazon-s3,boto3,Amazon Web Services,Amazon S3,Boto3,我正在尝试将所有内容从old\u prefix复制到new\u prefix中的s3中的同一个bucket中 old_prefix = 'path/old/chknzw/experiments/' new_prefix = 'path/new/hello_test/experiments/' 我看了这篇文章,写了以下代码: def test(bucket): s3 = boto3.resource('s3') old_prefix = 'path/old/chknzw/expe
old\u prefix
复制到new\u prefix
中的s3中的同一个bucket中
old_prefix = 'path/old/chknzw/experiments/'
new_prefix = 'path/new/hello_test/experiments/'
我看了这篇文章,写了以下代码:
def test(bucket):
s3 = boto3.resource('s3')
old_prefix = 'path/old/chknzw/experiments/'
new_prefix = 'path/new/hello_test/experiments/'
my_bucket = s3.Bucket(bucket)
for obj in my_bucket.objects.filter(Prefix=old_prefix):
old_source = { 'Bucket': my_bucket,
'Key': obj.key}
new_key = new_prefix + obj.key[len(old_prefix):]
print(new_key)
new_obj = my_bucket.Object(new_key)
new_obj.copy(old_source)
在我们复印的最后一行之前,一切似乎都很顺利。它抛出错误:
TypeError: expected string or bytes-like object
我遗漏了什么?错误在这一行:
old_source={'Bucket':我的_Bucket,
对于源规范,Bucket
应该是Bucket的名称,而不是Bucket对象:
old_source={'Bucket':Bucket,