How to change storage class of existing key via boto3

后端 未结 1 1815
时光取名叫无心
时光取名叫无心 2020-12-20 23:25

When using AWS S3 service, I need to change storage class of existing key from STANDARD to STANDARD_IA.

change_storage_class from boto doesn\'t exist in

相关标签:
1条回答
  • 2020-12-21 00:02

    from amazon doc

    You can also change the storage class of an object that is already stored in Amazon S3 by copying it to the same key name in the same bucket. To do that, you use the following request headers in a PUT Object copy request:

    • x-amz-metadata-directive set to COPY
    • x-amz-storage-class set to STANDARD, STANDARD_IA, or REDUCED_REDUNDANCY

    in term of boto3 copy code, this will look like

    import boto3
    
    s3 = boto3.client('s3')
    
    copy_source = {
        'Bucket': 'mybucket',
        'Key': 'mykey'
    }
    
    s3.copy(
      copy_source, 'mybucket', 'mykey',
      ExtraArgs = {
        'StorageClass': 'STANDARD_IA',
        'MetadataDirective': 'COPY'
      }
    )
    
    0 讨论(0)
提交回复
热议问题