Skip to content

Instantly share code, notes, and snippets.

@michalc
Created October 28, 2018 10:37
Show Gist options
  • Save michalc/1effe17a56f870a50148c764f242083b to your computer and use it in GitHub Desktop.
Save michalc/1effe17a56f870a50148c764f242083b to your computer and use it in GitHub Desktop.
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