Created
October 28, 2018 10:37
-
-
Save michalc/1effe17a56f870a50148c764f242083b to your computer and use it in GitHub Desktop.
PUTting an object to S3 using aiohttp and aws_sig_v4_headers
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
import asyncio | |
import os | |
import aiohttp | |
from aws_sig_v4_headers import aws_sig_v4_headers | |
async def main(): | |
method = 'PUT' | |
host = 's3-eu-west-1.amazonaws.com' | |
path = f'/my-bucket-name/my-object-key' | |
data = b'This is the data' | |
pre_auth_headers = {} | |
query = {} | |
headers = aws_sig_v4_headers(os.environ['AWS_ACCESS_KEY_ID'], os.environ['AWS_SECRET_ACCESS_KEY'], pre_auth_headers, | |
's3', 'eu-west-1', host, method, path, query, data) | |
async with aiohttp.ClientSession() as session: | |
async with session.request(method, f'https://{host}{path}', headers=headers, data=data) as response: | |
await response.read() | |
asyncio.get_event_loop().run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment