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 / configuration-regions-and-discovery

Configuration, regions, and endpoint discovery

Configuration and endpoint resolution give each asynchronous service client the settings and destination it needs before a request is sent. The session combines caller settings with shared configuration sources, then uses service and partition data to select an endpoint. Some services can replace that default destination with an endpoint learned at run time.

Configuration sources

Configuration is resolved at client creation. The session keeps shared settings while each client receives a final view that combines those settings with caller choices.

Session and client settings

The session is the main boundary for configuration loading. A caller can set a session default configuration or pass client-specific settings. Client settings override the session default for the same option. The resulting configuration also carries async client choices such as the HTTP session type and connection options. See aiobotocore/session.py• L187-215 and aiobotocore/config.py• L43-88.

The session resolves values that affect the target before it creates the client. This includes the region, certificate bundle, API version, endpoint settings, and default behavior mode. The client creator then receives one resolved configuration rather than a set of competing sources. See aiobotocore/session.py• L215-245 and aiobotocore/session.py• L280-331.

References: aiobotocore/session.py• L187-245 aiobotocore/session.py• L280-331 aiobotocore/config.py• L43-88

Configuration providers

A configuration provider is a source that resolves one named setting. The session's configuration store can use different providers for values such as the profile, region, data path, or certificate bundle. This separates the meaning of a setting from the source that supplies it. Provider changes therefore affect client creation without changing service code. See aiobotocore/session.py• L282-303 and tests/…/test_session.py• L65-105.

The store is copied for each client. Smart defaults are merged into that client-scoped view. This keeps a client's resolved settings stable while the session remains reusable for later clients. See aiobotocore/session.py• L280-303.

References: aiobotocore/session.py• L280-303 tests/…/test_session.py• L65-105

Smart default modes

Smart defaults choose a behavior profile when the configured defaults mode is not legacy. In auto mode the session first checks the current execution region. If that is not available it can ask instance metadata for a region. The result distinguishes an in-region call from a cross-region call. If no region is known the system uses the standard profile. See aiobotocore/configprovider.py• L4-37 and aiobotocore/session.py• L292-299.

These defaults change client behavior through the same configuration store used by explicit settings. They do not replace an explicit client choice. For example, the selected mode can supply a retry mode while a caller still controls the client region. See tests/test_configprovider.py• L6-20.

References: aiobotocore/configprovider.py• L4-37 aiobotocore/session.py• L292-303 tests/test_configprovider.py• L6-20

Region and partition resolution

Region resolution maps a service call to the AWS partition and service location that can handle it. Partition data describes regional endpoint patterns and related values such as DNS suffixes. The client uses this data with the selected service model and region before it builds request and signing context.

Region selection

The client region comes from the caller or from the session's configuration chain. The resolved value becomes client context for endpoint rules and signing. A service that needs a regional destination cannot complete endpoint or signing setup when no usable region is available. See aiobotocore/session.py• L215-225, aiobotocore/client.py• L381-400, and aiobotocore/args.py• L48-68.

The session can also report the regions that a service supports in a selected partition. Unknown services return no regions rather than creating a destination from incomplete data. See aiobotocore/session.py• L338-353.

References: aiobotocore/session.py• L215-225 aiobotocore/session.py• L338-353 aiobotocore/client.py• L381-400 aiobotocore/args.py• L48-68

Partition data

Partition data is the shared map that lets endpoint rules interpret a region. Service data supplies the service identity and endpoint rule set. The client loads both when the service supports modern endpoint rules. If the service has no rule set, the client uses the legacy endpoint resolver instead. See aiobotocore/client.py• L60-74 and aiobotocore/session.py• L149-179.

The partition is not only a routing label. It can provide values used to form the endpoint and to select the signing context. A change to a service or partition data set must therefore keep the destination and its authentication region consistent. See aiobotocore/args.py• L165-205.

References: aiobotocore/client.py• L60-74 aiobotocore/session.py• L149-179 aiobotocore/args.py• L165-205

Endpoint feature parameters

Endpoint rules use more than the region name. They can also use operation parameters, client context, and built-in feature values. These values represent choices such as FIPS endpoints, dual-stack endpoints, S3 addressing behavior, and account-based endpoint modes. The rules return the endpoint data that matches the complete request context. See aiobotocore/args.py• L191-245 and tests/…/test_args.py• L95-260.

An event hook can adjust built-in values before endpoint resolution. This provides a controlled override for integrations that need to alter endpoint behavior without changing the service model. See aiobotocore/regions.py• L67-116.

References: aiobotocore/args.py• L191-245 aiobotocore/regions.py• L67-116 tests/…/test_args.py• L95-260

Endpoint selection

Endpoint selection turns resolved service and request context into a URL. The selected endpoint can also return headers and properties for request construction and authentication. This decision sits between client preparation and request signing.

This diagram shows how a client chooses a normal endpoint before a request reaches the async transport.

flowchart LR
    A[Caller settings] --> B[Resolved region and configuration]
    C[Service model] --> D[Endpoint rules]
    E[Partition data] --> D
    B --> D
    F[Operation parameters] --> D
    D --> G[Endpoint URL]
    D --> H[Headers and endpoint properties]
    G --> I[Request signing and transport]
    H --> I

Service endpoint rules

A service endpoint rule set evaluates the operation, request parameters, client context, and built-in values. It returns a URL plus optional headers and properties. Properties can include authentication scheme data, so endpoint selection also supplies inputs for the signer. See aiobotocore/regions.py• L12-65 and aiobotocore/client.py• L521-571.

The resolver keeps endpoint evaluation async because some built-in values can come from async sources. It also adapts the rule result to the client's transport contract. A non-secure client receives an HTTP URL when the resolved rule produced an HTTPS URL and no explicit endpoint was supplied. See aiobotocore/regions.py• L26-65.

References: aiobotocore/regions.py• L12-65 aiobotocore/client.py• L521-571

Custom endpoint URLs

A caller-supplied endpoint URL is an explicit destination for the client. It is validated before the async HTTP session is created. This path is useful for local services and test systems, but it changes the normal endpoint lifecycle. See aiobotocore/session.py• L191-204 and aiobotocore/endpoint.py• L322-358.

Custom endpoint URLs also disable endpoint discovery registration. The client will continue to use the supplied destination instead of replacing it with a discovered service endpoint. See aiobotocore/client.py• L221-238 and tests/test_endpoint.py• L6-16.

References: aiobotocore/session.py• L191-204 aiobotocore/endpoint.py• L322-358 aiobotocore/client.py• L221-238 tests/test_endpoint.py• L6-16

Legacy endpoint routing

Services without a modern endpoint rule set use the legacy endpoint resolver. This fallback preserves service routing for older or incomplete service data. The resulting endpoint still supplies the base URL used to create the client's async endpoint. See aiobotocore/client.py• L60-74, aiobotocore/client.py• L85-110, and aiobotocore/args.py• L32-104.

Modern rules and legacy routing are alternative ways to find the base destination. A request can still apply service-specific changes after that choice, such as a region correction for an S3 bucket. The correction updates the request URL and signing context before a retry. See aiobotocore/utils.py• L564-613.

References: aiobotocore/client.py• L60-74 aiobotocore/client.py• L85-110 aiobotocore/args.py• L32-104 aiobotocore/utils.py• L564-613

Dynamic endpoint discovery

Endpoint discovery lets a service return a destination that cannot be known from static region data alone. A discovery-capable client calls the service's discovery operation when needed, caches the returned endpoints, and injects the selected endpoint into the request.

This diagram shows the normal discovery path and its fallbacks when a cached endpoint or refresh is not available.

sequenceDiagram
    participant Client
    participant Handler
    participant Cache
    participant Service
    Client->>Handler: Request with discovery identifiers
    Handler->>Cache: Look up endpoint
    alt Fresh endpoint exists
        Cache-->>Handler: Endpoint
    else Endpoint is missing or stale
        Handler->>Service: Describe endpoints
        Service-->>Handler: Endpoint list
        Handler->>Cache: Store refreshed endpoints
    end
    Handler-->>Client: Inject endpoint or use normal endpoint

Discovery enablement

Discovery is registered only when the service model declares a discovery operation and configuration enables the feature. The setting can come from client configuration or the configuration store. If discovery is disabled, operations that require it are blocked rather than sent to an unsuitable default endpoint. See aiobotocore/client.py• L221-250.

Optional discovery differs from required discovery. Optional discovery can leave the normal endpoint in place when discovery fails. Required discovery must obtain an endpoint or report a refresh failure. See aiobotocore/discovery.py• L29-70.

References: aiobotocore/client.py• L221-250 aiobotocore/discovery.py• L29-70

Discovery cache

The discovery manager keys cached endpoints by the identifiers supplied by the operation. It returns a current endpoint when one exists. When the entry is stale it refreshes the list unless a recent refresh failure is being held back. A stale endpoint can serve as a temporary fallback. See aiobotocore/discovery.py• L12-27 and aiobotocore/discovery.py• L41-68.

The handler changes the request URL only after discovery returns a usable endpoint. It adds an HTTPS scheme when the service returns a host without one. This keeps endpoint selection close to the request that needs it while leaving the normal client endpoint available as a fallback. See aiobotocore/discovery.py• L73-87.

References: aiobotocore/discovery.py• L12-27 aiobotocore/discovery.py• L41-68 aiobotocore/discovery.py• L73-87

Endpoint signing context

Endpoint selection and signing are linked. Endpoint properties can replace the default authentication scheme and can provide a signing region or signing name for the selected destination. The request signer then uses that context with the client's credentials or token. See aiobotocore/client.py• L547-569 and aiobotocore/args.py• L59-68.

This page covers where the destination and signing inputs come from. The identity providers and the signing step are described in Credentials, tokens, and signing. The wider relationship between these inputs is described in Identity and configuration.

References: aiobotocore/client.py• L547-569 aiobotocore/args.py• L59-68 aiobotocore/signers.py• L20-92

Change checklist

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

  • Changes to configuration provider precedence must preserve the handoff from session settings to the client-scoped configuration store.
  • Changes to region or partition data must keep endpoint URL values aligned with signing region, signing name, and supported endpoint features.
  • Changes to endpoint rule parameters must preserve the relationship between operation inputs, event-hook overrides, and request context.
  • Changes to custom endpoint handling must preserve the rule that a supplied URL skips endpoint discovery registration.
  • Changes to discovery enablement must preserve the difference between optional fallback and required-operation failure.
  • Changes to discovered endpoint caching must keep request identifiers, stale entries, refresh backoff, and endpoint injection consistent.

Important failure modes

TriggerConsequenceGuard
A regional service has no resolved regionEndpoint or signing setup fails before a valid request can be sentSet the region at the client or session boundary and verify its provider source
A service region is not supported by the selected partitionEndpoint rules cannot produce a usable destinationUse a region listed for the service and partition
Endpoint feature settings request an unsupported combinationEndpoint resolution returns an error instead of a URLKeep FIPS, dual-stack, S3, and account-based settings within the service model's supported choices
A custom endpoint URL is invalidClient creation fails before transport setupSupply a complete valid HTTP or HTTPS endpoint URL
Endpoint discovery is expected while a custom endpoint URL is suppliedDiscovery handlers are not registered and the custom URL remains authoritativeRemove the custom URL when service discovery is required
Required discovery cannot refresh and has no usable cache entryThe operation raises an endpoint-discovery refresh errorKeep the discovery operation reachable and preserve its identifiers
Endpoint rules return signing data that does not match the chosen destinationThe service rejects the request or signing failsTreat endpoint properties and signing context as one contract

Key files

FileWhy to read it
aiobotocore/session.pyShows the boundary where session settings, configuration providers, defaults, region selection, and client creation meet.
aiobotocore/config.pyDefines the async client configuration surface and its merge behavior.
aiobotocore/configprovider.pyShows how automatic smart defaults use the execution or metadata region.
aiobotocore/client.pyShows service data loading, endpoint resolver choice, request-time endpoint resolution, and discovery registration.
aiobotocore/args.pyShows how region, partition, endpoint, and signing inputs become client arguments.
aiobotocore/regions.pyShows the async service endpoint rules and their built-in parameter resolution.
aiobotocore/discovery.pyShows discovery refresh, caching, fallback, and request URL injection.
aiobotocore/endpoint.pyShows endpoint URL validation and creation of the async transport endpoint.
aiobotocore/utils.pyShows service-specific S3 region correction and endpoint re-resolution after a redirect.