Skip to content

Instantly share code, notes, and snippets.

@yaronf
Created December 13, 2017 07:28
Show Gist options
  • Save yaronf/35a3a86755280a7b2cad54ea135a0c77 to your computer and use it in GitHub Desktop.
Save yaronf/35a3a86755280a7b2cad54ea135a0c77 to your computer and use it in GitHub Desktop.
Pre-sign an S3 URL - Python
# 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