Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 递归地将s3对象从一个前缀复制到另一个前缀_Amazon Web Services_Amazon S3_Boto3 - Fatal编程技术网

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,