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.6.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.6.0
File Size Uploaded Provenance Actions
aws_credentials_sts-0.6.0.tar.gz 15.5 kB Without provenance Details for aws_credentials_sts-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 37.6 kB

Release files / aws_credentials_sts-0.6.0.tar.gz

Download URL aws_credentials_sts-0.6.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6419eadd52c17c989d0339adddf8ebb330bb6ab32fe56d83eb000ec94d91681d
BLAKE2b-256 checksum
How to use checksums
21f5abc90560961e0bf1f5ab5f2f0bd043b53c20adf9fe484c71273bccc8b4b1
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.6.0-py3-none-any.whl

Download URL aws_credentials_sts-0.6.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa338fba113b0446066f3721cf3c473d55b21c940f24b5dbdeac60f043420f70
BLAKE2b-256 checksum
How to use checksums
5a9df677a11c6afa5b54da2e5b39e8acd8f8ec215be17f7e4b47b70a1c7ed09d
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.6.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