forked from igobrilhante/aws-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-download-file.py
executable file
·33 lines (27 loc) · 1.13 KB
/
s3-download-file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import boto3
import botocore
import sys
import argparse
def download_file(bucket, objectkey, filepath ):
s3_client = boto3.client('s3')
try:
s3_client.download_file(bucket, objectkey, filepath)
print "Requested file saved at: %s" % filepath
except botocore.exceptions.ClientError as e:
if e.response['ResponseMetadata']['HTTPStatusCode'] == 404:
print "Requested file: %s/%s (not found)" % (bucket, objectkey)
else:
print "Error Msg: %s" % e.response['Error']['Message']
def main():
parser = argparse.ArgumentParser(description='Donwload file from AWS S3')
parser.add_argument('-b', '--bucket', required=True,
help="The bucket name.")
parser.add_argument('-o', '--objectkey', required=True,
help="The host string used to build the new name")
parser.add_argument('-f', '--filepath', required=True,
help="The filepath of the file to be saved" )
arg = parser.parse_args()
download_file(arg.bucket, arg.objectkey, arg.filepath)
if __name__ == '__main__':
sys.exit(main())