Created
December 13, 2017 07:28
-
-
Save yaronf/35a3a86755280a7b2cad54ea135a0c77 to your computer and use it in GitHub Desktop.
Pre-sign an S3 URL - Python
This file contains 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
# Boto setup: | |
# The file ~/.aws/credentials contains: | |
# [default] | |
# region=eu-west-1 | |
# aws_access_key_id=xxxxxx | |
# aws_secret_access_key=xxxxxx | |
import boto3 | |
import requests | |
from botocore.client import Config | |
# Get the service client. | |
s3 = boto3.client('s3', config=Config(signature_version='s3v4')) | |
# Generate the URL to get 'key-name' from 'bucket-name' | |
url = s3.generate_presigned_url( | |
ClientMethod='get_object', | |
Params={ | |
'Bucket': 'yaronf', | |
'Key': 'signedObject.txt' | |
} | |
) | |
print url | |
response = requests.get(url) | |
print response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment