简体   繁体   中英

How to change storage class of object in s3 bucket using boto3?

I am trying to change the storage class of an object in S3 from standard to IA This is similar to this thread. But I would like to do it using boto3 and lambda trigger.

thanks

You can use copy_object class:

You can use the CopyObject action to change the storage class of an object that is already stored in Amazon S3 using the StorageClass parameter.

For example:

import boto3

s3 = boto3.client('s3')

bucket_name = '<your bucket-name>'
object_key = '<your-object-key>'

r = s3.copy_object(
    CopySource=f"{bucket_name}/{object_key}",
    Bucket=bucket_name,
    Key=object_key,
    StorageClass='STANDARD_IA')
    
print(r)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM