【问题标题】:Does Amazon S3 check integrity when copying from a bucket to another?从存储桶复制到另一个存储桶时,Amazon S3 是否会检查完整性?
【发布时间】:2021-09-16 13:26:08
【问题描述】:

我有一个关于 Amazon S3 Copy 的问题,我在 Python 中使用 boto3。 当 AWS 在存储桶之间复制时,它会执行校验和还是验证复制对象的完整性? 我们是否应该相信如果它不报告错误,一切都会顺利进行?

检查复制过程是否正确的最佳方法是什么?

【问题讨论】:

标签: python amazon-web-services amazon-s3 boto3 checksum


【解决方案1】:

基本上你使用的是python Boto,我还假设你之前上传的文件是作为一个单独的部分上传的,那么你可以使用以下python snipet获取文件的md5

Boto 旧于版本 3

#bandwidth friendly no need to download content
md5_b1 = bucket1.get_key('your file name').etag[1 :-1]
md5_b2 = bucket2.get_key('your file name').etag[1 :-1]
if md5_b1 == md5_b2:
    print('Your file was coppied successfully no corruption')

Boto 版本 3(已测试)

对于boto3,可以使用以下实用函数在boto3==1.18.18上进行测试

def GetMD5(bucket, key):
        s3_cli = boto3.client('s3')
        response = s3_cli.head_object(Bucket=bucket, Key=key)
        return response['ResponseMetadata']['HTTPHeaders']['etag'].strip('"')

【讨论】:

  • 感谢您的回答!它看起来像旧的 bo​​to 代码,您确定它可以与 boto3 一起使用吗?
  • 我正在测试和试验
  • @Sebastian 检查我编辑的答案
猜你喜欢
  • 1970-01-01
  • 2013-09-06
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 2018-11-22
  • 1970-01-01
  • 2023-02-01
  • 2021-07-28
相关资源
最近更新 更多