sma*_*rds 5 python amazon-s3 amazon-web-services boto3
我需要将所有文件从 S3 中的一个前缀复制到同一存储桶中的另一个前缀。我的解决方案是这样的:
file_list = [List of files in first prefix]
for file in file_list:
copy_source = {'Bucket': my_bucket, 'Key': file}
s3_client.copy(copy_source, my_bucket, new_prefix)
Run Code Online (Sandbox Code Playgroud)
不过,我只移动 200 个小文件(每个 1 kb),此过程最多需要 30 秒。一定可以做得更快吗?
我会同时进行。例如:
from multiprocessing import Pool
file_list = [List of files in first prefix]
print(objects_to_download)
def s3_coppier(s3_file):
copy_source = {'Bucket': my_bucket, 'Key': s3_file}
s3_client.copy(copy_source, my_bucket, new_prefix)
# copy 5 objects at the same time
with Pool(5) as p:
p.map(s3_coppier, file_list)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3178 次 |
| 最近记录: |