Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PUTting an object to S3 using aiohttp and aws_sig_v4_headers
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
You can’t perform that action at this time.