Created
September 23, 2018 23:37
-
-
Save nmolivo/0e584d292b940bbfdf98cb700aacd3ab to your computer and use it in GitHub Desktop.
This file contains 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
#Save our s3 word docs to the EC2 instance | |
bucket_name = 'name_of_s3_bucket' # replace with your bucket name | |
session = Session(aws_access_key_id=ACCESS_KEY, | |
aws_secret_access_key=SECRET_KEY) | |
s3 = session.resource('s3') | |
#for loop to loop through all files in the file_list and downlaod them to the EC2 instance. | |
for word_doc in file_list: | |
#word_doc is the name of our file, as a string. | |
KEY = word_doc | |
ec2_file_name = "../ec2docs/"+word_doc[5:] | |
try: | |
s3.Bucket(bucket_name).download_file(KEY, ec2_file_name) | |
except botocore.exceptions.ClientError as e: | |
if e.response['Error']['Code'] == "404": | |
continue | |
#print("The object does not exist.") | |
else: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment