Skip to content

Instantly share code, notes, and snippets.

@gsomoza
Last active August 6, 2018 12:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsomoza/7c69a6331001b5b7375e6aa28700e474 to your computer and use it in GitHub Desktop.
Save gsomoza/7c69a6331001b5b7375e6aa28700e474 to your computer and use it in GitHub Desktop.
S3: Create Presigned Download URL
#!/usr/bin/env python
# Usage:
# s3-presign-url path/to/object
#
# 1) Install boto3:
# pip install boto3
# 2) Configure aws:
# aws configure
# 3) Change the bucket name in this script (below)
#
import boto3
import requests
import sys
# argument
key = sys.argv[1]
# Get the service client.
s3 = boto3.client('s3')
# Generate the URL to get 'key-name' from 'bucket-name'
url = s3.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': 'mslb-db-backups',
'Key': key
}
)
# Use the URL to perform the GET operation. You can use any method you like
# to send the GET, but we will use requests here to keep things simple.
response = requests.get(url)
print response.url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment