aws-assume-role-lib simplifies assumed role session chaining with automatic credential refreshing for boto3. As of version 2.10.0, released May 14, 2022, it provides an abstraction layer over `sts.AssumeRole` to handle credential expiration and session name generation, common in serverless environments like AWS Lambda. The library maintains a steady release cadence, with updates addressing new boto3 features and CLI support.
pip install aws-assume-role-libVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a parent `boto3` session and then use `aws_assume_role_lib.assume_role` to get a new session with assumed role credentials. The assumed session automatically handles credential refreshing. Ensure the `ROLE_ARN` environment variable is set or replace the placeholder.
Review how `region_name` is used in `assume_role` calls. Explicitly set `region_name=True` to fix the child session's region to the parent's current value, or pass a specific string for a fixed region.
If you relied on the `botocore`-generated `RoleSessionName` when `SourceIdentity` was present, set `RoleSessionName` to `aws_assume_role_lib.AUTOMATIC_ROLE_SESSION_NAME` to restore the pre-2.8 behavior.
For performance-critical paths where input validity is guaranteed, you can disable this validation by passing `validate=False` to the `assume_role` call.
Be aware of these type differences when migrating code or referencing `boto3`'s `AssumeRole` documentation. Leverage the convenient Python types for easier policy and duration management.
Utilize `aws-assume-role-lib.assume_role()` for automatic credential refreshing and session name generation, which is particularly beneficial in long-running processes or serverless functions.
Install the package using pip: 'pip install aws-assume-role-lib'.
Ensure the import statement is correct: 'from aws_assume_role_lib import assume_role'.
Update the IAM policy to grant 'sts:AssumeRole' permission for the specified role.
Refresh the credentials by re-assuming the role or obtaining new temporary credentials.
Provide the 'RoleArn' parameter when calling 'assume_role', e.g., 'assume_role(session, RoleArn="arn:aws:iam::123456789012:role/MyRole")'.