aiobotocore
aiobotocore is an asyncio-native, mostly feature-complete async wrapper around botocore, enabling non-blocking AWS service calls via aiohttp (with experimental httpx support). Current version is 3.3.0. Releases track botocore closely — minor/patch releases drop frequently (often weekly) to relax or bump the botocore dependency range, with occasional minor releases adding features like socket_factory support in AioConfig.
Common errors
-
ModuleNotFoundError: No module named 'aiobotocore'
cause The 'aiobotocore' library is not installed in the Python environment.fixInstall 'aiobotocore' using pip: 'pip install aiobotocore'. -
AttributeError: module 'aiobotocore' has no attribute 'AioSession'
cause The 'AioSession' attribute does not exist in the 'aiobotocore' module.fixUse 'aiobotocore.session.get_session()' to create a session instead. -
AttributeError: 'ClientCreatorContext' object has no attribute 'send_message'
cause The 'create_client' method returns a coroutine that needs to be awaited.fixAwait the 'create_client' coroutine: 'client = await session.create_client('sqs')'. -
aiobotocore==X.Y.Z requires botocore<A.B.C,>=D.E.F but botocore G.H.I was resolved
cause There is a version incompatibility between 'aiobotocore' and 'botocore' (or 'boto3'), often due to other installed packages requiring different 'botocore' versions.fixUse a virtual environment to isolate dependencies and explicitly pin compatible versions of 'aiobotocore', 'botocore', and 'boto3' in your project's dependencies. -
botocore.exceptions.NoCredentialsError: Unable to locate credentials
cause The aiobotocore client, inheriting from botocore, cannot find valid AWS credentials in the standard locations (environment variables, shared credentials file, IAM role).fixEnsure AWS credentials are configured properly, typically via environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`), a shared credentials file (`~/.aws/credentials`), or an IAM role attached to the execution environment.
Warnings
- breaking create_client() MUST be used as an async context manager (async with). Calling it without a context manager and manually closing is unreliable, and since v3.0.0 creating a new ClientSession after the client exits its context is explicitly forbidden and raises an error.
- breaking The aiobotocore[boto3] and aiobotocore[awscli] packaging extras were removed in v3.0.0. Installing them will raise a pip error about unknown extras.
- breaking Credential properties (credentials.access_key, credentials.secret_key, credentials.token) raise NotImplementedError because they do not trigger an async refresh cycle.
- gotcha aiobotocore pins botocore to a narrow version range that changes with every release. Installing aiobotocore alongside boto3, awscli, s3fs, or moto frequently causes pip dependency conflicts because those packages independently pin botocore.
- gotcha get_object() response Body must be consumed inside an async context manager. Reading Body outside of 'async with response["Body"] as stream:' can leave the underlying TCP connection dangling and cause connection pool exhaustion.
- gotcha Paginators are async iterators in aiobotocore. You must use 'async for result in paginator.paginate(...):', NOT a regular 'for' loop. A regular for loop will not await pages and silently yields nothing or raises TypeError.
- deprecated Passing the 'loop' parameter to get_session() is a legacy pattern from pre-asyncio.run() era and is no longer supported. Python's asyncio manages the event loop implicitly.
- breaking AWS error: AuthorizationHeaderMalformed. This usually means that AWS credentials (Access Key ID and Secret Access Key) are not configured correctly or are missing in the environment where the code is running. Common causes include missing environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) or an improperly configured AWS credentials file (~/.aws/credentials).
Install
-
pip install aiobotocore -
pip install aiobotocore boto3 -
pip install 'types-aiobotocore[essential]'
Imports
- get_session
import aiobotocore; aiobotocore.get_session(loop=loop)
from aiobotocore.session import get_session
- AioSession
from aiobotocore.session import AioSession
- AioConfig
from aiobotocore.config import AioConfig
- AIOHTTPSession
from aiobotocore.httpsession import AIOHTTPSession
- HttpxSession
from aiobotocore.httpxsession import HttpxSession
- ClientError
import botocore.exceptions; botocore.exceptions.ClientError
Quickstart
import asyncio
import os
from aiobotocore.session import get_session
import botocore.exceptions
async def main():
session = get_session()
async with session.create_client(
's3',
region_name='us-east-1',
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
) as client:
try:
response = await client.list_buckets()
for bucket in response.get('Buckets', []):
print(bucket['Name'])
except botocore.exceptions.ClientError as e:
print(f"AWS error: {e.response['Error']['Code']} - {e.response['Error']['Message']}")
except botocore.exceptions.NoCredentialsError:
print('No credentials found')
asyncio.run(main())