如何克隆使用Python(和博托)在Amazon S3中的关键? [英] How to clone a key in Amazon S3 using Python (and boto)?

查看:121
本文介绍了如何克隆使用Python(和博托)在Amazon S3中的关键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含在我的S3存储桶的重要文件。我想创建一个新的密钥,其中将包含相同的文件。是否有可能这样做,而无需下载该文件? 我在寻找在Python(和preferably博托库)的解决方案。

解决方案

 从boto.s3.key导入密钥

从桶的名字#获取信号源键
source_key = source_bucket.get_key(source_key_name)

#Copy信号源键到一个新桶新的键名(可以是相同的源)
#Note:source_key是关键
source_key.copy(dest_bucket_name,dest_key_name)

博托的Key类的#系统签名:
高清拷贝(个体经营,dst_bucket,dst_key,元数据=无,
             reduced_redundancy =假,preserve_acl =假,
             encrypt_key =假,validate_dst_bucket =真)

#设置preserve_acl = True以从源头键复制ACL
 

I have a file contained in a key in my S3 bucket. I want to create a new key, which will contain the same file. Is it possible to do without downloading that file? I'm looking for a solution in Python (and preferably boto library).

解决方案

from boto.s3.key import Key

#Get source key from bucket by name
source_key = source_bucket.get_key(source_key_name)

#Copy source key to a new bucket with a new key name (can be the same as source)
#Note: source_key is Key
source_key.copy(dest_bucket_name,dest_key_name)

#The signature of boto's Key class:
def copy(self, dst_bucket, dst_key, metadata=None,
             reduced_redundancy=False, preserve_acl=False,
             encrypt_key=False, validate_dst_bucket=True)

#set preserve_acl=True to copy the acl from the source key

这篇关于如何克隆使用Python(和博托)在Amazon S3中的关键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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