【问题标题】:how to update metadata on an S3 object larger than 5GB?如何更新大于 5GB 的 S3 对象的元数据?
【发布时间】:2020-10-06 00:07:50
【问题描述】:

我正在使用 boto3 API 来更新对象的 S3 元数据。

我正在使用How to update metadata of an existing object in AWS S3 using python boto3?

我的代码如下所示:

    s3_object = s3.Object(bucket,key)
    new_metadata = {'foo':'bar'}
    s3_object.metadata.update(new_metadata)
    s3_object.copy_from(CopySource={'Bucket':bucket,'Key':key}, Metadata=s3_object.metadata, MetadataDirective='REPLACE')

当对象大于 5GB 时,此代码将失败。我收到此错误:

botocore.exceptions.ClientError: An error occurred (InvalidRequest) when calling the CopyObject operation: The specified copy source is larger than the maximum allowable size for a copy source: 5368709120

如何更新大于 5GB 的对象的元数据?

【问题讨论】:

    标签: amazon-s3 boto3


    【解决方案1】:

    由于对象的大小,请尝试调用分段上传并使用 copy_from 参数。有关详细信息,请参阅此处的 boto3 文档:

    https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.MultipartUploadPart.copy_from

    【讨论】:

    • 但是我没有上传对象...?
    【解决方案2】:

    显然,您不能只更新元数据 - 您需要将对象重新复制到 S3。您可以将其从 s3 复制回 s3,但不能只更新,这对于 100-500GB 范围内的对象来说很烦人。

    【讨论】:

      猜你喜欢
      • 2017-07-16
      • 2022-12-10
      • 1970-01-01
      • 2012-07-31
      • 2011-06-12
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多