Observed since 21 Oct, 11:41 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Easily create aioboto3 assume role sessions with automatic credential refreshing.
Easily create aioboto3 assume role sessions with automatic credential refreshing.
NOTE - For
boto3support, see boto3-assume.
Install with pip:
$ pip install aioboto3-assume
import aioboto3
from aioboto3_assume import assume_role
assume_session = assume_role(
source_session=aioboto3.Session(), # You must pass in an aioboto3 session that automatically refreshes!
assume_role_kwargs={
"RoleArn": "arn:aws:iam::123412341234:role/my_role",
"RoleSessionName": "my-role-session"
}
)
async def main():
# Create clients, and their credentials will auto-refresh when expired!
async with assume_session.client("sts", region_name="us-east-1") as sts_client:
print(await sts_client.get_caller_identity())
# {
# "UserId": "EXAMPLEID",
# "Account": "123412341234",
# "Arn": "arn:aws:sts::123412341234:role/my_role",
# "ResponseMetadata": {
# "RequestId": "asdfqwfqwfasdfasdfasfsdf",
# "HTTPStatusCode": 200,
# "HTTPHeaders": {
# "server": "amazon.com",
# "date": "Tue, 27 Jun 2023 00:00:00 GMT"
# },
# "RetryAttempts": 0
# }
# }
asyncio.run(main())
Under the hood an aioboto3 sts client will be created and assume_role called to get/refresh credentials.
You can pass the kwargs parameters as so:
assume_role_kwargs - Keyword arguments to pass when calling assume_role with a boto3 STS client.
RoleArn and RoleSessionName as outlined in the boto3 docs.sts_client_kwargs - Kwargs to pass when creating the boto3 low level client for STS
"sts".service_name or credentials here.target_session_kwargs - Keyword arguments to pass when creating a the new target boto3 Session
region_name or aws_account_id or other variables that will not effect credentials or credential refreshing.A more complex example:
import aioboto3
from aioboto3_assume import assume_role
from botocore.config import Config
assume_session = assume_role(
source_session=aioboto3.Session(),
assume_role_kwargs={
"RoleArn": "arn:aws:iam::123412341234:role/my_role",
"RoleSessionName": "my-role-session",
"DurationSeconds": 900,
"Tags": [
{
"Key": "MyKey",
"Value": "MyValue"
}
]
},
sts_client_kwargs={
"config": Config(
retries={
"total_max_attempts": 10,
"mode": "adaptive"
}
)
},
target_session_kwargs={
"region_name": "us-east-1"
}
)
Install the package in editable mode with dev dependencies.
(venv) $ pip install -e .[dev]
nox is used to manage various dev functions. Start with
(venv) $ nox --help
pyenv is used to manage python versions. To run the nox tests for applicable python version you will first need to install them. In the root project dir run:
(venv) $ pyenv install
Changelog for aioboto3-assume.
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
assume_roleInitial Release.
Split from boto3-assume package.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.2 | 15 Jan 2026 | 11 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 11:41 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:aeb229394906d18e55200f7cd1840031d0e916a8290ab5f478f6930f96c859d0