Created
July 26, 2021 13:33
-
-
Save eercanayar/e5f8fa65d1be447e0a5f450977f8a441 to your computer and use it in GitHub Desktop.
Amazon S3 download folder with prefix, boto3, python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import os | |
bucket_name = '<bucket-name>' | |
s3_prefix = '<prefix>' | |
s3_resource = boto3.resource('s3') | |
bucket = s3_resource.Bucket(bucket_name) | |
for obj in bucket.objects.filter(Prefix = s3_prefix): | |
if not os.path.exists(os.path.dirname(obj.key)): | |
os.makedirs(os.path.dirname(obj.key)) | |
bucket.download_file(obj.key, obj.key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment