I wanted to download specific folder content from a S3 bucket. I am able to access s3 bucket but how can I access folder and download the content in the folder to my local drive.
ACCESS_KEY = 'def'
SECRET_KEY = 'abc'
session = Session(aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3')
your_bucket = s3.Bucket('bucket_name')
filename = []
for s3_file in your_bucket.objects.all():
filename.append(s3_file.key)
s3 = boto3.client('s3',aws_access_key_id = ACCESS_KEY,aws_secret_access_key= SECRET_KEY)
for l in range(len(filename)):
s3.download_file('bucket_name',filename[l],'filepath'+filename[l])
The above code is used to access the content from the Aws s3 bucket. In my s3 bucket there are multiple folders I need to select the specific folder and download contents only from that folder. How can I do this?