Skip to content

Instantly share code, notes, and snippets.

@namuan
Forked from heitorlessa/presign_url.py
Created January 3, 2019 09:25
Show Gist options
  • Save namuan/11e55e35f22a0c154f2921f696ce6e5c to your computer and use it in GitHub Desktop.
Save namuan/11e55e35f22a0c154f2921f696ce6e5c 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment