Skip to content

Instantly share code, notes, and snippets.

@ksatirli
Created November 10, 2017 10:20
Show Gist options
  • Save ksatirli/6b8cdfeb4a13d558f328caca50ef332c to your computer and use it in GitHub Desktop.
Save ksatirli/6b8cdfeb4a13d558f328caca50ef332c to your computer and use it in GitHub Desktop.
generate signed URL for AWS S3

generate a signed URL for AWS S3 Bucket Objects by calling this script the following way:

python s3-generate-signed-url.py "us-west-1" "my-bucket" "index.html"

The output will look something like this:

Region: us-west-1
Bucket: my-bucket
File: index.html

https://s3.amazonaws.com/my-bucket/index.html?Signature=RpC...%3D&Expires=1510312662&AWSAccessKeyId=AKI...CLA
import sys
import boto
import boto.s3.connection
print
print "Region: " + sys.argv[1]
print "Bucket: " + sys.argv[2]
print "File: " + sys.argv[3]
print
s3connection = boto.s3.connect_to_region(sys.argv[1], is_secure=True, calling_format=boto.s3.connection.OrdinaryCallingFormat())
bucket = s3connection.get_bucket(sys.argv[2])
key = bucket.get_key(sys.argv[3])
print key.generate_url(3600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment