You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用boto3从S3 GLACIER_IR取回对象遇ObjectNotInActiveTierError求助

问题描述

我已通过以下boto3代码成功将S3对象复制到GLACIER_IR存储类:

copy_source = {'Bucket': obj['Bucket'], 'Key': obj['Key']}
s3.copy(CopySource=copy_source, Bucket=bucket, Key=filename_w_timestamp, StorageClass='GLACIER_IR')

但使用类似代码取回该文件时,出现错误:

botocore.errorfactory.ObjectNotInActiveTierError: An error occurred (ObjectNotInActiveTierError) when calling the CopyObject operation: The source object of the COPY operation is not in the active tier and is only stored in Amazon Glacier.

我的取回代码如下:

s3.copy(CopySource=copy_source, Bucket=bucket, Key=filename_w_timestamp)

恳请帮忙排查问题所在。

问题原因与解决方法

原因

GLACIER_IR(Glacier即时检索)属于S3归档存储类,这类对象默认不在活跃访问层,CopyObject操作仅支持直接处理活跃层的对象,因此直接复制会触发错误。

解决步骤

  1. 发起对象取回请求
    先调用restore_object将GLACIER_IR中的对象临时恢复到活跃层:

    s3.restore_object(
        Bucket=copy_source['Bucket'],
        Key=copy_source['Key'],
        RestoreRequest={
            'Days': 7,  # 恢复后在活跃层保留的天数,可按需调整
            'GlacierJobParameters': {
                'Tier': 'Expedited'  # 取回优先级:Expedited(最快,数小时)/Standard(1-2天)/Bulk(5-7天,成本最低)
            }
        }
    )
    
  2. 等待取回任务完成
    发起请求后需等待任务结束,可通过head_object检查恢复状态:

    import time
    
    while True:
        response = s3.head_object(Bucket=copy_source['Bucket'], Key=copy_source['Key'])
        if 'Restore' in response and 'ongoing-request="false"' in response['Restore']:
            break
        time.sleep(60)  # 每分钟检查一次,可根据所选取回 tier 调整间隔
    
  3. 执行复制操作
    确认对象恢复完成后,再运行你的复制代码即可成功取回:

    s3.copy(CopySource=copy_source, Bucket=bucket, Key=filename_w_timestamp)
    

额外提示

  • 若需长期频繁访问该对象,建议复制后将目标对象存储在活跃类(如STANDARD),避免重复取回的成本和等待时间。
  • 不同取回Tier对应不同的费用和速度,可根据业务需求选择合适的选项。

内容的提问来源于stack exchange,提问作者python_enthusiast

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 07:03:30