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

查看:543
本文介绍了使用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天全站免登陆