Introducing a new way to review your PRs.

Read the announcement

aio-libs / aiobotocore

asyncio support for botocore library using aiohttp

View on GitHub

18 documents · Updated Nov 20, 2026

docs / identity-and-configuration

Identity and configuration

Identity and configuration prepare an asynchronous AWS client to call the right service with the right authority. The session combines caller settings, region and service data, credential or token providers, signing rules, and endpoint discovery before the request reaches the HTTP layer.

Call preparation

The call-preparation flow turns session and client inputs into an endpoint and an authentication context. Each part supplies data to the next part, so a valid service call needs both a location and an identity unless the selected operation is unsigned.

This diagram shows how configuration and identity data meet at client creation and then shape each service request.

flowchart LR
    A[Session and client settings] --> B[Resolved configuration]
    C[Credential providers] --> D[Credentials]
    E[Token providers] --> F[Auth token]
    G[Service and region data] --> H[Endpoint and signing context]
    B --> H
    D --> I[Request signer]
    F --> I
    H --> I
    I --> J[Authenticated service request]
    K[Endpoint discovery] --> J

Session inputs

home/…/session.py defines AioSession as the coordination point for client preparation. A client call can receive a region, endpoint URL, TLS setting, credentials, token-related state, and an AioConfig; the session merges client configuration with its default configuration before it resolves the remaining values.

The session applies values at the boundary between shared session state and one client. It resolves the region and CA bundle, selects the credential source, loads an authentication token, applies smart defaults when enabled, and passes the resulting context to the client creator.

References: aiobotocore/session.py• L44-119 aiobotocore/session.py• L187-331 aiobotocore/config.py• L43-88

Credential and token identity

Credentials identify a caller with an access key, secret key, and optional session token. The session uses an asynchronous provider chain that can draw from explicit values, environment and profile data, role exchange, web identity, SSO, login sessions, process output, container metadata, or instance metadata; the first provider that returns credentials supplies the client identity.

Some providers return refreshable credentials. Role exchange, SSO, metadata, environment, process, and login sources can refresh temporary identity data while several async tasks use the same credentials. An authentication token is a separate identity input used by services whose selected auth scheme requires one. Token providers can load or refresh SSO tokens, while refreshable credentials and tokens protect shared state during concurrent use. The detailed provider and refresh behavior belongs in Credentials, tokens, and signing.

References: aiobotocore/credentials.py• L83-193 aiobotocore/credentials.py• L340-499 aiobotocore/credentials.py• L935-1123 aiobotocore/credentials.py• L1278-1502 aiobotocore/tokens.py• L25-35 aiobotocore/tokens.py• L38-95

Region and endpoint context

Region data connects a service operation to its AWS partition, endpoint, signing region, and signing name. The client creator combines service metadata, partition data, the resolved region, client context, and endpoint settings to build this context; services without endpoint rules use the legacy endpoint path.

Configuration defaults can use the current execution region or instance metadata to distinguish in-region and cross-region calls. Endpoint rules then resolve operation and client parameters before built-in values such as region and feature flags. The full loading and endpoint decision model is described in Configuration, regions, and endpoint discovery.

References: aiobotocore/configprovider.py• L4-37 aiobotocore/client.py• L42-110 aiobotocore/args.py• L125-141 aiobotocore/regions.py• L67-101

Signing context

The client creates a request signer with the endpoint’s signing region, signing name, signature version, credentials, and optional auth token. For each request, the signer lets operation context and event hooks adjust the signer choice before it obtains a frozen credential or token and adds authentication to the request.

Unsigned mode is a deliberate path for calls that use another form of proof, such as a web identity token or an SSO access token exchanged with an identity service. If the selected auth scheme needs a regional AWS signature and no region exists, signing stops with a region error rather than sending an invalid request.

References: aiobotocore/args.py• L59-68 aiobotocore/client.py• L79-107 aiobotocore/signers.py• L20-92 aiobotocore/signers.py• L94-177

Endpoint discovery

Endpoint discovery supplies a service-specific endpoint after the client has a normal endpoint and authentication context. When a service supports discovery, the client registers discovery behavior only when configuration enables it; a custom endpoint URL skips that behavior.

The discovery manager caches endpoints by request identifiers and refreshes stale entries when needed. Optional discovery can fall back to the default endpoint, while a required operation raises an endpoint-discovery error if no usable endpoint is available.

References: aiobotocore/client.py• L221-250 aiobotocore/discovery.py• L12-70 aiobotocore/discovery.py• L73-87

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to client or session configuration precedence must preserve the handoff of the final region, CA bundle, signature mode, and endpoint settings to client creation.
  • Changes to credential or token providers must preserve provider order, the identity type expected by the selected auth scheme, and the async refresh contract used during signing.
  • Changes to service endpoint or partition data must keep endpoint region, signing region, signing name, and signature version aligned.
  • Changes to endpoint discovery settings must preserve the distinction between optional discovery, required discovery, and custom endpoint URLs.
  • Changes to endpoint rules or request context must account for both endpoint selection and the signing values derived from that selection.

Important failure modes

TriggerConsequenceGuard
Only one of an explicitly supplied access key or secret key is presentClient creation raises a partial-credentials errorSupply both explicit key values or allow the provider chain to resolve identity
No credential provider returns an identity for a signed callThe request cannot obtain frozen credentials and cannot be authenticatedCheck the active profile, environment, role source, or metadata source
A configured login session lacks its required support dependencyCredential loading raises a missing-dependency errorInstall the required botocore CRT support before using the login provider
A regional signing scheme has no resolved regionSigning raises a region error before the request is sentSet the client or session region and verify endpoint rules preserve it
Credential or token refresh fails during its mandatory refresh windowThe service call fails instead of using expired identity dataKeep the source token or credential service available and refresh before expiry
Required endpoint discovery cannot refresh and has no cached endpointThe operation raises an endpoint-discovery refresh errorEnable discovery for the service and keep its discovery operation reachable
A custom endpoint URL is used while expecting endpoint discoveryDiscovery handlers are not registered and the custom URL remains in useTreat a custom URL as authoritative or remove it when discovery is required

Key files

FileWhy to read it
aiobotocore/session.pyShows how session settings, credentials, tokens, regions, defaults, and client creation meet.
aiobotocore/config.pyDefines the async client configuration surface and its merge and validation rules.
aiobotocore/credentials.pyShows the asynchronous credential provider chain, role and token-backed sources, and refresh model.
aiobotocore/tokens.pyShows token provider selection and refresh behavior.
aiobotocore/args.pyShows how endpoint data and identity become client signing and endpoint context.
aiobotocore/signers.pyShows how the selected auth scheme uses credentials or tokens to authenticate requests.
aiobotocore/regions.pyShows how service endpoint rules obtain region and operation context.
aiobotocore/discovery.pyShows how discovered endpoints are refreshed, cached, selected, and injected.
aiobotocore/client.pyShows service model selection, endpoint data loading, auth selection, and discovery registration.