如何重命名对象 boto3 S3? [英] How to rename objects boto3 S3?

查看:35
本文介绍了如何重命名对象 boto3 S3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 S3 中有大约 1000 个以命名的对象

I have about 1000 objects in S3 which named after

abcyearmonthday1
abcyearmonthday2
abcyearmonthday3
...

想将它们重命名为

abc/year/month/day/1
abc/year/month/day/2
abc/year/month/day/3

我怎么能通过 boto3 做到这一点.有没有更简单的方法?

how could I do it through boto3. Is there easier way of doing this ?

推荐答案

Boto3/S3:使用 copy_object 重命名对象

您不能在 S3 中重命名对象,您必须使用新名称复制对象,然后删除旧对象

you can not rename an object in S3 you have to copy object with a new name and then delete the Old object

s3 = boto3.resource('s3')
s3.Object('my_bucket','my_file_new').copy_from(CopySource='my_bucket/my_file_old')
s3.Object('my_bucket','my_file_old').delete()

这篇关于如何重命名对象 boto3 S3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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