简体   繁体   English

如何下载 S3 存储桶中的文件

[英]How to download files in an S3 bucket

How to copy all files that start with a prefix.如何复制所有以前缀开头的文件。 I have a lot of files with the name 2021 - ** - **.我有很多名为 2021 - ** - ** 的文件。 You need to download them for a certain period.您需要在一段时间内下载它们。 This commands did not help这个命令没有帮助

aws s3 sync s3://my-bucket/2021-04-12-* .
aws s3 cp s3://my-bucket/2021-04-12-* .

Use python3 script使用python3脚本

import boto3
import os

s3 = boto3.resource('s3')
my_bucket = s3.Bucket('my-bucket')

for my_bucket_object in my_bucket.objects.all():
    # Assume your bucket structure as s3://my-bucket/<files> 
    if my_bucket_object.key.startswith('2021-04-12-'):
        os.system(f'aws s3 cp s3://my-bucket/{my_bucket_object.key} .')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM