IAM Roles Anywhere Session
This package provides an easy way to create a refreshable boto3 Session with IAM Roles Anywhere, without defining an AWS profile with relevant configuration for IAM roles anywhere.
This package implements the algorithm described here: https://docs.aws.amazon.com/rolesanywhere/latest/userguide/authentication-sign-process.html.
Requirements
- Python 3.9 or later
- Creation and configuration of a trust anchor. See documentation
- Valid X.509 certificate, private key, and optionally a certificate chain file associated with your trust anchor
Install
- From PyPi
pip install iam-rolesanywhere-session
- From source
git clone https://github.com/awslabs/iam-roles-anywhere-session.git
cd iam-roles-anywhere-session
python3 -m pip install ./
Configuration
For this package to work you will need to have at your disposal your certificate and private_key file in a PEM format.
IAMRoleAnywhereSession will take multiple arguments:
| Name | Description | Type | Default value |
|---|---|---|---|
| profile_arn | The Amazon Resource Name (ARN) of the profile. | string | None |
| role_arn | The Amazon Resource Name (ARN) of the role to assume. | string | None |
| trust_anchor_arn | The Amazon Resource Name (ARN) of the trust anchor. | string | None |
| certificate | The x509 certificate file, in PEM format. | path or bytes | None |
| private_key | The certificate private key file, in PEM Format. | path or bytes | None |
| certificate_chain | The intermediate certificate chain, in PEM format. Sent as X-Amz-X509-Chain. |
path or bytes | None |
| private_key_passphrase | The passphrase use to decrypt private key file. | string | None |
| region | The name of the region where you configured IAM Roles Anywhere. | string | us-east-1 |
| session_duration | The duration, in seconds, of the role session. Must be between 900 (15 minutes) and 43200 (12 hours). The effective ceiling is the lower of the profile's durationSeconds and the role's MaxSessionDuration. |
int | 3600 |
| service_name | An identifier for the service, used to build the botosession. | string | rolesanywhere |
| endpoint | Roles Anywhere API endpoint to use. Resolved from the region and partition when omitted. | string | resolved per region/partition |
| use_fips_endpoint | Use the FIPS 140-3 validated endpoint for the region. | bool | False |
| verify | Whether to validate TLS certificates, or the path to a trusted certificate authority. Applies to the credential request and to clients created from the session. | bool or str | True |
| proxies | Proxy endpoint(s) for use behind private networks with a proxy. | dict | {} |
| proxies_config | A dictionary of additional proxy configurations. | dict | {} |
| role_session_name | Session name recorded in CloudTrail. Requires acceptRoleSessionName on the profile. |
string | None |
| instance_properties | Key/value properties describing the workload. Requires requireInstanceProperties on the profile. |
dict | None |
from iam_rolesanywhere_session import IAMRolesAnywhereSession
roles_anywhere_session = IAMRolesAnywhereSession(
profile_arn="arn:aws:rolesanywhere:eu-central-1:111122223333:profile/a6294488-77cf-4d4a-8c5c-40b96690bbf0",
role_arn="arn:aws:iam::111122223333:role/IAMRolesAnywhere-01",
trust_anchor_arn="arn:aws:rolesanywhere:eu-central-1:111122223333:trust-anchor/4579702c-9abb-47c2-88b2-c734e0b29539",
certificate='certificate.pem',
private_key='privkey.pem',
region="eu-central-1"
).get_session()
s3 = roles_anywhere_session.client("s3")
print(s3.list_buckets())
Documentation
The complete documentation covers additional usage examples and the module reference.
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the Apache 2
Metadata
Release files for iam-rolesanywhere-session 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| iam_rolesanywhere_session-3.0.0.tar.gz | 44.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iam_rolesanywhere_session-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.5 kB
Release files / iam_rolesanywhere_session-3.0.0.tar.gz
| Download URL | iam_rolesanywhere_session-3.0.0.tar.gz |
|---|---|
| Size | 44.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5972cbf5bcbdd9796a749b5401fad3e691f860222690c37a280aadf9c534abff
|
|
BLAKE2b-256 checksum How to use checksums |
eee33f88a43c0d23cf9202e2d9e8c40d01ea539efb145fe3726dca404ca29a87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.
Transparency logRelease files / iam_rolesanywhere_session-3.0.0-py3-none-any.whl
| Download URL | iam_rolesanywhere_session-3.0.0-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e3750d8c46816d075c3f31139ec302d918b33990196bb7fdb3d693592e3237c
|
|
BLAKE2b-256 checksum How to use checksums |
ada09b4fa7242791e9f8ca1ad0fbdc77a8e13723de2f44b893e5bf6b3160644b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.
Transparency log