使用 boto3 在 Amazon S3 上的文件夹之间移动文件(指定的存储桶不存在错误)

Move files between folder on Amazon S3 using boto3 ( The specified bucket does not exist error)

我正在尝试使用 boto3 在文件夹之间移动文件,为此使用 boto3,示例在这里

    s3_resource = boto3.resource('s3')
    # Copy object A as object B
    s3_resource.Object('dev-files', 'your-folder/my.txt').copy_from(
        CopySource='my-folder/my.txt')
    # Delete the former object A
    s3_resource.Object('dev-files', 'my-folder/my.txt').delete()

并收到此错误:(

调用CopyObject操作时发生错误(NoSuchBucket):指定的bucket不存在

CopySource参数定义为:

The string form is {bucket}/{key} or {bucket}/{key}?versionId={versionId} if you want to copy a specific version. You can also provide this value as a dictionary. The dictionary format is recommended over the string format because it is more explicit. The dictionary format is: {'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}. Note that the VersionId key is optional and may be omitted.

因此这一行:

CopySource='my-folder/my.txt')

开头应包含存储桶名称:

CopySource='dev-files/my-folder/my.txt')