Last active
August 6, 2018 12:45
-
-
Save gsomoza/7c69a6331001b5b7375e6aa28700e474 to your computer and use it in GitHub Desktop.
S3: Create Presigned Download URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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