Using Boto3 Python SDK
, I was able to download files using the method bucket.download_file()
Is there a way to download an entire folder?
Advertisement
Answer
quick and dirty but it works:
JavaScript
x
11
11
1
import boto3
2
import os
3
4
def downloadDirectoryFroms3(bucketName, remoteDirectoryName):
5
s3_resource = boto3.resource('s3')
6
bucket = s3_resource.Bucket(bucketName)
7
for obj in bucket.objects.filter(Prefix = remoteDirectoryName):
8
if not os.path.exists(os.path.dirname(obj.key)):
9
os.makedirs(os.path.dirname(obj.key))
10
bucket.download_file(obj.key, obj.key) # save to same path
11
Assuming you want to download the directory foo/bar from s3 then the for-loop will iterate all the files whose path starts with the Prefix=foo/bar.