Skip to content

Instantly share code, notes, and snippets.

@eercanayar
Created July 26, 2021 13:33
Show Gist options
  • Save eercanayar/e5f8fa65d1be447e0a5f450977f8a441 to your computer and use it in GitHub Desktop.
Save eercanayar/e5f8fa65d1be447e0a5f450977f8a441 to your computer and use it in GitHub Desktop.
Amazon S3 download folder with prefix, boto3, python3
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