如何克隆使用Python(和博托)在Amazon S3中的关键?关键、Python、Amazon

2023-09-11 09:18:47 作者:以守为攻

我已经包含在我的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).

解决方案 亚马逊s3的使用方法 使用Amazon S3 –第一部分

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