-
-
Save vfulco/79a525ee02ae5b327de9 to your computer and use it in GitHub Desktop.
Generate signed URL's for S3 objects from the command line (requires .boto file for credentials)
This file contains hidden or 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
#!/usr/bin/python | |
import boto, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-b','--bucket', help='Name of your S3 Bucket', required=True) | |
parser.add_argument('-o','--object', help='Name of the object + prefix in your bucket', required=True) | |
parser.add_argument('-t','--time', type=int, help='Expirery in seconds Default = 60', default=60) | |
args = vars(parser.parse_args()) | |
def get_signed_url(time, bucket, obj): | |
s3 = boto.connect_s3() | |
url = s3.generate_url( | |
time, | |
'GET', | |
bucket, | |
obj, | |
response_headers={ | |
'response-content-type': 'application/octet-stream' | |
} | |
) | |
return url | |
try: | |
url = get_signed_url(args['time'],args['bucket'], args['object']) | |
print url | |
except: | |
print 'Something odd happened' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment