如何使用Python(和boto)在Amazon S3中克隆密钥?

Tho*_*tep 16 python amazon-s3 boto

我的S3存储桶中的密钥中包含一个文件.我想创建一个新密钥,它将包含相同的文件.是否可以不下载该文件?我在寻找Python的解决方案(最好是boto库).

Ada*_*son 15

bucket是目标存储区的位置:

bucket.copy_key(new_key,source_bucket,source_key)
Run Code Online (Sandbox Code Playgroud)


Ami*_*mor 10

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
Run Code Online (Sandbox Code Playgroud)


wha*_*ick 2

S3 允许逐个对象复制。当您指定源对象的键和存储桶以及目标目的地的键和存储桶时,CopyObject 操作会创建对象的副本。不确定 boto 是否有紧凑的实现。