Package: aioboto3
Breaking changes for v11: The S3Transfer config passed into upload/download_file etc.. has been updated to that it matches what boto3 usesBreaking changes for v9: aioboto3.resource and aioboto3.client methods no longer exist, make a session then call session.client etc…This was done for various reasons but mainly that it prevents the default session living longer than it should as that breaks situations where eventloops are replaced.The .client and .resource functions must now be used as async context managers.Now that aiobotocore has reached version 1.0.1, a side effect of the work put in to fix various issues like bucket region redirection and
supporting web assume role type credentials, the client must now be instantiated using a context manager, which by extension applies to
the resource creator. You used to get away with callingres =aioboto3.resource('dynamodb')but that no longer works. If you really want
to do that, you can dores = awaitaioboto3.resource('dynamodb').__aenter__()but you’ll need to remember to call__aexit__.There will most likely be some parts that dont work now which I’ve missed, just make an issue and we’ll get them resoved quickly.Creating service resources must also be async now, e.g.asyncdefmain():session=aioboto3.Session()asyncwithsession.resource("s3")ass3:bucket=awaits3.Bucket('mybucket')# <----------------asyncfors3_objectinbucket.objects.all():print(s3_object)Updating to aiobotocore 1.0.1 also brings with it support for running inside EKS as well as asyncifyingget_presigned_urlThis package is mostly just a wrapper combining the great work ofboto3andaiobotocore.aiobotocore allows you to use near enough all of the boto3 client commands in an async manner just by prefixing the command withawait.With aioboto3 you can now use the higher level APIs provided by boto3 in an asynchronous manner. Mainly I developed this as I wanted to use the boto3 dynamodb Table object in some async
microservices.While all resources in boto3 should work I havent tested them all, so if what your after is not in the table below then try it out, if it works drop me an issue with a simple test case
and I’ll add it to the table.ServicesStatusDynamoDB Service ResourceTested and workingDynamoDB TableTested and workingS3WorkingKinesisWorkingSSM Parameter StoreWorkingAthenaWorkingExampleSimple example of using aioboto3 to put items into a dynamodb tableimportasyncioimportaioboto3fromboto3.dynamodb.conditionsimportKeyasyncdefmain():session=aioboto3.Session()asyncwithsession.resource('dynamodb',region_name='eu-central-1')asdynamo_resource:table=awaitdynamo_resource.Table('test_table')awaittable.put_item(Item={'pk':'test1','col1':'some_data'})result=awaittable.query(KeyConditionExpression=Key('pk').eq('test1'))# Example batch writemore_items=[{'pk':'t2','col1':'c1'},\{'pk':'t3','col1':'c3'}]asyncwithtable.batch_writer()asbatch:foritem_inmore_items:awaitbatch.put_item(Item=item_)loop=asyncio.get_event_loop()loop.run_until_complete(main())# Outputs:#  [{'col1': 'some_data', 'pk': 'test1'}]Things that either dont work or have been patchedAs this library literally wraps boto3, its inevitable that some things won’t magically be async.Fixed:s3_client.download_file*This is performed by the s3transfer module. – Patched with get_objects3_client.upload_file*This is performed by the s3transfer module. – Patched with custom multipart uploads3_client.copyThis is performed by the s3transfer module. – Patched to use get_object -> upload_fileobjectdynamodb_resource.Table.batch_writerThis now returns an async context manager which performs the same functionResource waiters - You can now await waiters which are part of resource objects, not just client waiters, e.g.await dynamodbtable.wait_until_exists()Resource object properties are normally autoloaded, now they are all co-routines and the metadata they come from will be loaded on first await and then cached thereafter.S3 Bucket.objects object now works and has been asyncified. Examples here -https://aioboto3.readthedocs.io/en/latest/usage.html#s3-resource-objectsAmazon S3 Client-Side EncryptionBoto3 doesn’t support AWS client-side encryption so until they do I’ve added basic support for it. Docs hereCSECSE requires the pythoncryptographylibrary so if you dopip install aioboto3[s3cse]that’ll also include cryptography.This library currently supports client-side encryption using KMS-Managed master keys performing envelope encryption
using either AES/CBC/PKCS5Padding or preferably AES/GCM/NoPadding. The files generated are compatible with the Java Encryption SDK
so I will assume they are compatible with the Ruby, PHP, Go and C++ libraries as well.Non-KMS managed keys are not yet supported but if you have use of that, raise an issue and i’ll look into it.DocumentationDocs are here -https://aioboto3.readthedocs.io/en/latest/Examples here -https://aioboto3.readthedocs.io/en/latest/usage.htmlFeaturesClosely mimics the usage of boto3.TodoMore examplesSet up docsLook into monkey-patching the aws xray sdk to be more async if it needs to be.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.
It also makes use of theaiobotocoreandboto3libraries. All the credit goes to them, this is mainly a wrapper with some examples.