如何通过boto3更改现有密钥的存储类 [英] How to change storage class of existing key via boto3

查看:115
本文介绍了如何通过boto3更改现有密钥的存储类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AWS S3服务时,我需要将现有密钥的存储类从STANDARD更改为STANDARD_IA.

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

change_storage_class.

Boto3的等效功能是什么?

What is the equivalent in Boto3?

推荐答案

来自 amazon doc

您还可以通过将对象复制到同一存储桶中的相同键名来更改已存储在Amazon S3中的对象的存储类.为此,您可以在PUT Object复制请求中使用以下请求标头:

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设置为COPY
  • x-amz-storage-class设置为STANDARDSTANDARD_IAREDUCED_REDUNDANCY
  • x-amz-metadata-directive set to COPY
  • x-amz-storage-class set to STANDARD, STANDARD_IA, or REDUCED_REDUNDANCY

关于boto3 复制代码,看起来像

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'
  }
)

这篇关于如何通过boto3更改现有密钥的存储类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆