Skip to content

Instantly share code, notes, and snippets.

@heitorlessa
Created January 11, 2017 16:11
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save heitorlessa/ea2450684b050ecc3cfe789db1717bb9 to your computer and use it in GitHub Desktop.
Save heitorlessa/ea2450684b050ecc3cfe789db1717bb9 to your computer and use it in GitHub Desktop.
Quick and dirty S3 Presign URL using Python Boto3 and Click
import boto3
import click
@click.command()
@click.argument("bucket")
@click.argument("key")
@click.option("-e", "--expiration", default=3600, type=int, help="How long this presigned URL will live for")
def presign_s3(bucket, key, expiration):
""" Simple utility to generate presigned URL on S3 (Default 1 hour expiration)
\b
Common Usage:
python presign_url.py myS3Bucket Key -e 28800
python presign_url.py myS3Bucket Key
"""
params = {
'Bucket': bucket,
'Key': key
}
s3 = boto3.client('s3')
url = s3.generate_presigned_url('get_object', Params=params, ExpiresIn=expiration)
click.echo(url, nl=False)
if __name__ == '__main__':
presign_s3()
@TheGardenMan
Copy link

Hi where should I specify my credentials? Like access_key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment