Endpoint and HTTP transport
Endpoint and HTTP transport turn an async service operation into a network request and return its HTTP result to the request pipeline. Endpoint rules select the destination. A session backend then manages connections, proxy use, TLS, timeouts, response streams, and cleanup without blocking the async runtime. This page is a child of Request execution and connects to AWS requests and responses and Protocol parsing and checksums.
Endpoint resolution
Endpoint resolution maps a service operation and its call parameters to a URL plus the request context needed for signing. Service endpoint rules take priority when they apply. The client endpoint is the fallback. The resolved destination becomes part of the prepared request before dispatch. See aiobotocore/client.py• L381-413 and aiobotocore/client.py• L521-571.
The endpoint creator validates the final URL and selects the configured transport backend. Aiohttp is the default. Callers can select the HTTPX backend through AioConfig(http_session_cls=...). See aiobotocore/endpoint.py• L322-371 and aiobotocore/config.py• L43-88.
References: aiobotocore/client.py• L381-413 aiobotocore/client.py• L521-571 aiobotocore/endpoint.py• L322-371 aiobotocore/config.py• L43-88
Request dispatch
Request dispatch sends a prepared request through the selected session and keeps retry control above the transport layer. Event handlers can provide a response before network I/O. If no handler does so, the session sends the request. Each retry creates a new signed request and resets the request stream before the next attempt. See aiobotocore/endpoint.py• L95-153 and aiobotocore/endpoint.py• L183-251.
The transport returns an async AWS response wrapper. The endpoint converts it to the response shape used by the client. Successful streaming bodies stay open for the caller. Error bodies are read so protocol parsing can create the modeled error. See aiobotocore/endpoint.py• L30-66 and aiobotocore/client.py• L431-451.
This diagram shows the path from endpoint choice to a parsed service result.
flowchart LR
A[Service operation] --> B[Endpoint rules]
B --> C[Prepared signed request]
C --> D{Before-send response?}
D -- Yes --> E[Response processing]
D -- No --> F[HTTP session]
F --> E
E --> G[Protocol parser]
G --> H{Retry needed?}
H -- Yes --> C
H -- No --> I[Client result or modeled error]
References: aiobotocore/endpoint.py• L30-66 aiobotocore/endpoint.py• L95-153 aiobotocore/endpoint.py• L183-251 aiobotocore/client.py• L431-451
aiohttp transport
The aiohttp transport is the default asyncio backend. It creates one session for each proxy choice and reuses that session's connection pool for requests with the same choice. A lock coordinates session and connector creation when tasks send requests at the same time. See aiobotocore/httpsession.py• L70-123 and aiobotocore/httpsession.py• L231-247.
The transport maps request headers and bodies to aiohttp inputs. It keeps chunked transfer explicit and disables automatic content decompression. Non-streaming responses are consumed before return. Streaming responses remain tied to the pooled connection until the caller consumes or closes them. See aiobotocore/httpsession.py• L272-343 and aiobotocore/response.py• L131-184.
The session treats cleanup as an idempotent operation. A second close after a defensive close does not raise and therefore does not replace the caller's original exception. See aiobotocore/httpsession.py• L124-142.
References: aiobotocore/httpsession.py• L70-142 aiobotocore/httpsession.py• L231-247 aiobotocore/httpsession.py• L272-343 aiobotocore/response.py• L131-184
HTTPX transport
The HTTPX transport is an alternative async backend that can run with asyncio or Trio through AnyIO. It uses one shared async client and mounts proxy transports by URL scheme. This keeps connection limits shared while each request still uses its selected proxy. The client is created lazily after the session enters its async context, and a lock prevents concurrent first use from creating more than one client. See aiobotocore/httpxsession.py• L297-396.
HTTPX is loaded in two steps. The maintained httpx2 package is preferred. The original httpx package is a deprecated fallback and emits one warning per process when used. If neither package is installed, the optional backend is unavailable. See aiobotocore/_httpx.py• L1-28 and aiobotocore/httpxsession.py• L125-139.
The HTTPX transport preserves request targets when object-key paths require exact encoding. For proxied requests, it exposes the raw target to the endpoint request but not to the CONNECT request. It also adapts byte content and sync or async iterables to the async request interface. Its response wrapper follows the same async response contract as aiohttp. See aiobotocore/httpxsession.py• L55-89 and aiobotocore/httpxsession.py• L436-523.
References: aiobotocore/httpxsession.py• L55-89 aiobotocore/httpxsession.py• L113-139 aiobotocore/httpxsession.py• L297-396 aiobotocore/httpxsession.py• L436-523 aiobotocore/awsrequest.py• L33-41
Connection and timeout behavior
Connection settings control how long a request can wait for a connection or response and how many connections the pool can hold. The client timeout is the default. A request context can provide a per-request read timeout while the session keeps the configured connection timeout. See aiobotocore/httpsession.py• L252-270, aiobotocore/httpxsession.py• L411-434, and tests/test_httpsession.py• L103-174.
Transport errors are mapped to botocore error types so retry handling remains independent of the backend. Connection, proxy, TLS, read-timeout, and closed-stream failures remain distinct at the public error boundary. HTTPX also searches nested exception causes for TLS errors so a failed handshake has the same error meaning as it does in the aiohttp backend. See aiobotocore/httpsession.py• L344-376, aiobotocore/httpxsession.py• L92-110, aiobotocore/httpxsession.py• L525-563, and aiobotocore/_endpoint_helpers.py• L9-37.
References: aiobotocore/httpsession.py• L252-270 aiobotocore/httpsession.py• L344-376 aiobotocore/httpxsession.py• L92-110 aiobotocore/httpxsession.py• L411-434 aiobotocore/httpxsession.py• L525-563 aiobotocore/_endpoint_helpers.py• L9-37 tests/test_httpsession.py• L103-174
Proxy and TLS behavior
Botocore resolves configured and environment proxies before either backend sends the request. The HTTP backends do not read proxy environment variables themselves. This keeps proxy bypass decisions in one place. See aiobotocore/httpsession.py• L272-288, aiobotocore/httpxsession.py• L439-445, and tests/test_proxy.py• L361-381.
Endpoint TLS and proxy TLS are separate concerns. The endpoint context controls endpoint verification and the endpoint client certificate. An HTTPS proxy uses its own context with its own trust bundle and optional client certificate. The endpoint certificate is not offered during the proxy handshake. See aiobotocore/httpsession.py• L144-229, aiobotocore/httpxsession.py• L246-295, and tests/test_proxy.py• L228-356.
Endpoint verification can use system or configured CA trust, disable verification, and check host names. A client certificate can still be sent when endpoint verification is disabled. Certificate and trust-file work runs outside the event loop when needed. See aiobotocore/httpsession.py• L181-229, aiobotocore/httpxsession.py• L196-227, aiobotocore/httpxsession.py• L317-329, and tests/test_tls.py• L25-102.
References: aiobotocore/httpsession.py• L144-229 aiobotocore/httpsession.py• L272-288 aiobotocore/httpxsession.py• L196-227 aiobotocore/httpxsession.py• L246-295 aiobotocore/httpxsession.py• L317-329 aiobotocore/httpxsession.py• L439-445 tests/test_proxy.py• L228-356 tests/test_proxy.py• L361-381 tests/test_tls.py• L25-102
Asynchronous lifecycle
An HTTP session is an async resource owned by the client context. Endpoint cleanup closes the selected transport session. The aiohttp backend tracks its proxy-specific sessions in an async exit stack. The HTTPX backend enters its shared client lazily and closes it through the same lifecycle boundary. See aiobotocore/endpoint.py• L69-93, aiobotocore/httpsession.py• L124-142, and aiobotocore/httpxsession.py• L297-409.
This lifecycle prevents use after the client context exits and closes partially created HTTPX resources when setup fails. Streaming response bodies have a separate async close path. Callers must close a body when they stop reading before it reaches the end. See tests/test_httpsession.py• L14-30, tests/test_proxy.py• L40-67, and aiobotocore/response.py• L36-64.
References: aiobotocore/endpoint.py• L69-93 aiobotocore/httpsession.py• L124-142 aiobotocore/httpxsession.py• L297-409 aiobotocore/response.py• L36-64 tests/test_httpsession.py• L14-30 tests/test_proxy.py• L40-67
Change checklist
When these files or sections are changed, remember to consider these:
- Keep endpoint rule output, signing context, and transport URL aligned when endpoint properties or auth schemes change.
- Keep equivalent aiohttp and HTTPX failures mapped to the same botocore error class so retry handling remains backend-independent.
- Keep endpoint TLS credentials separate from proxy TLS credentials. A change to one handshake must not expose its certificate or trust settings to the other.
- Keep proxy selection in botocore and preserve its bypass behavior when changing backend client construction.
- Keep raw request-target handling aligned with proxy CONNECT behavior so exact object-key paths do not change the proxy authority.
- Keep streaming response close behavior aligned with connection-pool reuse for both response body types.
- Keep backend-specific timeout overrides consistent with the request context contract.
- Keep HTTPX client creation lazy, shared, and protected against concurrent first use.
- Keep repeated aiohttp close calls harmless so cleanup errors do not replace the user's operation error.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Invalid endpoint URL | Client creation fails before request dispatch | Validate the endpoint in AioEndpointCreator |
| Missing or invalid proxy CA or client certificate | Proxy setup fails before or during the first request | Use proxy-specific TLS settings and surface InvalidProxiesConfigError or its transport wrapper |
| Untrusted or mismatched endpoint certificate | The request fails as a TLS error | Use the right CA bundle or disable verification only when intended |
| Proxy cannot connect or cannot reach the target | The request fails as a proxy connection error | Keep proxy failures distinct from endpoint failures |
| A streaming body is abandoned without close | A pooled connection remains tied to the response | Consume the body or use its async context manager |
| HTTP session is used after client context exit | Transport access fails because its session state is closed | Keep requests inside the client async context |
| HTTPX first use races across tasks | More than one client or pool can be created | Keep async client creation behind the session lock |
| A raw request target is reused for proxy CONNECT | The proxy receives the object path as its authority | Apply the raw target only to the endpoint request |
| Cleanup runs twice on an aiohttp session | A second cleanup can mask the original operation error if it is not idempotent | Preserve the closed-session guard in AIOHTTPSession |
Key files
| File | Why to read it |
|---|---|
| aiobotocore/client.py | Shows how operation inputs become a resolved endpoint and prepared request. |
| aiobotocore/endpoint.py | Shows the shared endpoint flow, retry boundary, response conversion, and backend selection. |
| aiobotocore/httpsession.py | Shows the default aiohttp connection, proxy, TLS, timeout, error, and cleanup model. |
| aiobotocore/httpxsession.py | Shows the HTTPX and AnyIO connection, proxy, TLS, timeout, raw-target, error, and cleanup model. |
| aiobotocore/_httpx.py | Shows optional HTTPX backend selection and legacy-package behavior. |
| aiobotocore/response.py | Shows the async streaming response contract and backend-specific stream cleanup. |
| aiobotocore/config.py | Shows how callers choose a backend and validate connector settings. |
| tests/test_proxy.py | Demonstrates proxy routing and the separation of proxy and endpoint TLS. |
| tests/test_tls.py | Demonstrates endpoint trust, hostname checks, and client certificate behavior. |