Skip to content

Instantly share code, notes, and snippets.

@vfulco
Forked from richarvey/signed_url.py
Created January 25, 2016 06:47
Show Gist options
  • Save vfulco/79a525ee02ae5b327de9 to your computer and use it in GitHub Desktop.
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)
#!/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