import boto3
import os
from pathlib import Path
session = boto3.Session(
aws_access_key_id='AK...',
aws_secret_access_key='SK...'
# region = 'us-east-1'
)
s3_resource = session.resource('s3')
bucket = s3.Bucket('bucket-name')
key = 'prefix-name'
objs = list(bucket.objects.filter(Prefix=key))
for obj in objs:
# print(obj.key)
# remove the file name from the object key
obj_path = os.path.dirname(obj.key)
# create nested directory structure
Path(obj_path).mkdir(parents=True, exist_ok=True)
# save file with full path locally
bucket.download_file(obj.key, obj.key)
最后修改:2021 年 06 月 01 日 02 : 38 PM
© 允许规范转载