使用 boto3 在两个 AWS S3 存储桶之间移动文件 [英] Move files between two AWS S3 buckets using boto3

查看:47
本文介绍了使用 boto3 在两个 AWS S3 存储桶之间移动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用 Python Boto API 将文件在一个存储桶之间移动到另一个存储桶.(我需要它从第一个存储桶剪切"文件并将其粘贴"到第二个存储桶中).最好的方法是什么?

I have to move files between one bucket to another with Python Boto API. (I need it to "Cut" the file from the first Bucket and "Paste" it in the second one). What is the best way to do that?

** 注意:如果我有两个不同的 ACCESS KEYS 和 SECRET KEYS 有关系吗?

** Note: Is that matter if I have two different ACCESS KEYS and SECRET KEYS?

推荐答案

如果您使用的是 boto3(较新的 boto 版本),这很简单

If you are using boto3 (the newer boto version) this is quite simple

import boto3
s3 = boto3.resource('s3')
copy_source = {
    'Bucket': 'mybucket',
    'Key': 'mykey'
}
s3.meta.client.copy(copy_source, 'otherbucket', 'otherkey')

(文档)

这篇关于使用 boto3 在两个 AWS S3 存储桶之间移动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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