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

查看:17
本文介绍了如何通过 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 中不存在.

change_storage_class from boto doesn't exist in boto3.

Boto3 中的等价物是什么?

What is the equivalent in Boto3?

推荐答案

来自 亚马逊文档

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

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天全站免登陆