Skip to main content

aws-credentials-sts

This package provides STS-based credential resolvers and chain providers:

  • AssumeRoleCredentialsResolver - assumes an explicit role_arn using credentials from a source_resolver.
  • ProfileAssumeRoleCredentialsResolver - assumes a role configured in a named profile in the shared config/credentials files.
  • WebIdentityCredentialsResolver - assumes role_arn with an OIDC token read from web_identity_token_file, using STS AssumeRoleWithWebIdentity.

Each resolver and provider has an async equivalent in aws_credentials_sts.aio.

Installation

uv pip install aws-credentials-sts

Once installed, the providers register themselves with the SDK's modular credential chain. When a client resolves credentials through the default chain, unless a higher-precedence source resolves credentials first, it will:

  • assume a role with web identity when the AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN environment variables are set, and AWS_ROLE_SESSION_NAME optionally names the session. This is skipped when a profile is selected explicitly.
  • assume the role configured in the active profile (role_arn/source_profile/credential_source).
  • assume a role with web identity configured in the active profile (web_identity_token_file/role_arn/role_session_name).

Client Configuration

To use this resolver explicitly, set the aws_credentials_identity_resolver property on a service client's config to an AssumeRoleCredentialsResolver instance. It assumes role_arn using credentials from the source_resolver:

from aws_credentials_sts import AssumeRoleCredentialsResolver
from smithy_aws_core.identity import EnvironmentCredentialsResolver

service_client = ServiceClient(
    config=ServiceClientConfig.resolve(
        aws_credentials_identity_resolver=AssumeRoleCredentialsResolver(
            source_resolver=EnvironmentCredentialsResolver(),
            role_arn="arn:aws:iam::123456789012:role/example-role",
        ),
    )
)

To assume the role defined in a named profile instead, use ProfileAssumeRoleCredentialsResolver with a MergedConfig loaded from the shared config/credentials files:

from aws_credentials_sts import ProfileAssumeRoleCredentialsResolver
from smithy_aws_core.config import load_config


def build_client() -> ServiceClient:
    return ServiceClient(
        config=ServiceClientConfig.resolve(
            aws_credentials_identity_resolver=ProfileAssumeRoleCredentialsResolver(
                profile_name="my-profile",
                config_file=load_config(),
            ),
        )
    )

To assume a role with web identity explicitly, use WebIdentityCredentialsResolver. The token file is read each time the credentials are refreshed, so a token rotated on disk is picked up:

from aws_credentials_sts import WebIdentityCredentialsResolver

service_client = ServiceClient(
    config=ServiceClientConfig.resolve(
        aws_credentials_identity_resolver=WebIdentityCredentialsResolver(
            role_arn="arn:aws:iam::123456789012:role/example-role",
            web_identity_token_file="/var/run/secrets/token",
        ),
    )
)

Standalone

Any resolver can also be used on its own to fetch credentials directly:

import asyncio

from aws_credentials_sts.aio import AsyncAssumeRoleCredentialsResolver
from smithy_aws_core.aio.identity import AsyncEnvironmentCredentialsResolver


async def main() -> None:
    resolver = AsyncAssumeRoleCredentialsResolver(
        source_resolver=AsyncEnvironmentCredentialsResolver(),
        role_arn="arn:aws:iam::123456789012:role/example-role",
    )
    identity = await resolver.get_identity(properties={})


asyncio.run(main())

Metadata

Release files for aws-credentials-sts 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-credentials-sts 0.5.0
File Size Uploaded Provenance Actions
aws_credentials_sts-0.5.0.tar.gz 15.3 kB Without provenance Details for aws_credentials_sts-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-credentials-sts 0.5.0
File Interpreter ABI Platform Actions
aws_credentials_sts-0.5.0-py3-none-any.whl Python 3 none any Details for aws_credentials_sts-0.5.0-py3-none-any.whl

Total release size: 37.4 kB

Release files / aws_credentials_sts-0.5.0.tar.gz

Download URL aws_credentials_sts-0.5.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4c5eb8dfee30ea89bbe8ea99073e20e1be9f3f7dba048841ec86112cad67249e
BLAKE2b-256 checksum
How to use checksums
05009501c454513a8350a301bc7bbe314e878a4d1fc59d221ba2035a1ecfba58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / aws_credentials_sts-0.5.0-py3-none-any.whl

Download URL aws_credentials_sts-0.5.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f64dbf880f9507b2d207531c2fd226bc6f183e693dfb0cbcf9cfe5cd317f4d27
BLAKE2b-256 checksum
How to use checksums
c5e396d5d7a0a41f4dc035f2324765ff702e60e7343803e6b67fc152af96f40a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for aws-credentials-sts 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page