Skip to content

Instantly share code, notes, and snippets.

@nmolivo
Created September 23, 2018 23:36
Show Gist options
  • Save nmolivo/40f6d3a43300724079eb7c49bb7b971f to your computer and use it in GitHub Desktop.
Save nmolivo/40f6d3a43300724079eb7c49bb7b971f to your computer and use it in GitHub Desktop.
### Create list of files to download to EC2 Instance
from boto3.session import Session
ACCESS_KEY='your_access_key'
SECRET_KEY='your_secret_key'
session = Session(aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3')
your_bucket = s3.Bucket('name_of_s3_bucket')
file_list = []
for s3_file in your_bucket.objects.all():
#if in docs folder, and a file name greater than 5 characters, add to list.
if str(s3_file.key)[0:4] == "docs" and len(str(s3_file.key)) > 5:
file_list.append(str(s3_file.key))
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment