diff --git a/.agents/skills/building-lambda-functions-with-powertools-python/SKILL.md b/.agents/skills/building-lambda-functions-with-powertools-python/SKILL.md index 7d151a88d90..96054b87af6 100644 --- a/.agents/skills/building-lambda-functions-with-powertools-python/SKILL.md +++ b/.agents/skills/building-lambda-functions-with-powertools-python/SKILL.md @@ -196,7 +196,7 @@ These come from the project's architecture decision records. | Event Handler: AppSync Events | [references/event-handler-appsync-events.md](references/event-handler-appsync-events.md) | | Event Handler: Bedrock Agents | [references/event-handler-bedrock-agents.md](references/event-handler-bedrock-agents.md) | | Parameters and secrets | [references/parameters.md](references/parameters.md) | -| Auth (alpha): JWT verification, OAuth2 client | [references/auth-jwt-oauth2.md](references/auth-jwt-oauth2.md) | +| Auth: JWT verification, OAuth2 client, SigV4 request signing | [references/auth-jwt-oauth2.md](references/auth-jwt-oauth2.md) | | Batch processing | [references/batch-processing.md](references/batch-processing.md) | | Kafka consumer | [references/kafka.md](references/kafka.md) | | Typing | [references/typing.md](references/typing.md) | diff --git a/.agents/skills/building-lambda-functions-with-powertools-python/references/auth-jwt-oauth2.md b/.agents/skills/building-lambda-functions-with-powertools-python/references/auth-jwt-oauth2.md index 7cee6cc922d..166779bf307 100644 --- a/.agents/skills/building-lambda-functions-with-powertools-python/references/auth-jwt-oauth2.md +++ b/.agents/skills/building-lambda-functions-with-powertools-python/references/auth-jwt-oauth2.md @@ -1,7 +1,7 @@ - + # Auth Jwt Oauth2 -Source of truth: https://docs.powertools.aws.dev/lambda/python/latest/utilities/auth/, https://docs.powertools.aws.dev/lambda/python/latest/utilities/oauth2/ +Source of truth: https://docs.powertools.aws.dev/lambda/python/latest/utilities/auth/, https://docs.powertools.aws.dev/lambda/python/latest/utilities/oauth2/, https://docs.powertools.aws.dev/lambda/python/latest/utilities/signer/ Auth verifies JWT access tokens in any Lambda workload. Use `verify()` directly, create Event Handler middleware with `require()`, or build a Lambda authorizer response with `authorize()`. @@ -889,3 +889,209 @@ async def check_stock(sku: str) -> dict: Package `client_credentials.py` alongside the tool and register `check_stock` with an authenticated MCP server. The SDK owns transport authentication and error responses. Cancelling the task does not stop the worker's request; timeouts still apply. Install the MCP SDK separately. + +Sign HTTP requests to IAM-protected AWS endpoints with [Signature Version 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv4_signing.html), using the `botocore` the Lambda runtime already ships. Part of the Auth utility, next to [JWT verification](auth.md) and the [OAuth2 client](oauth2.md). + +## Key features + +* Sign a request and get back the headers and URL to send, with any HTTP client +* Drop-in `auth=` objects for `requests` and `httpx` that sign every call +* Region and credentials read from the Lambda environment, no credential provider chain on the cold start path +* S3 canonical rules applied when the service is S3 +* SigV4a for multi-region endpoints such as S3 Multi-Region Access Points, behind an optional extra + +## Getting started + +### Install + +Nothing to install for SigV4: the signer only needs `botocore`, which the Lambda runtime provides. If you package your function without the runtime's `boto3`, add `aws-lambda-powertools[aws-sdk]`. + +SigV4a needs the `awscrt` package, which the runtime does not ship: + +```bash +pip install "aws-lambda-powertools[auth-sigv4a]" +``` + +### Sign requests with `requests` + +Pass `requests_auth()` as `auth=` and every request through that session is signed on the way out. The example calls an API Gateway REST API with IAM authorization; the signing name for API Gateway is `execute-api`. + +**requests_client.py** + +```python +import os + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +ORDERS_API = os.environ["ORDERS_API_URL"] # API Gateway REST API with IAM authorization + +# Region and credentials come from the Lambda execution environment +orders_api = SigV4Signer(service="execute-api") +http = requests.Session() +http.auth = orders_api.requests_auth() # every request through this session is signed + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + response = http.post(f"{ORDERS_API}/orders", json={"customer_id": event["customer_id"]}, timeout=5) + response.raise_for_status() + return response.json() +``` + +### Sign requests with `httpx` + +`httpx_auth()` does the same for `httpx`. This example calls a Lambda Function URL with `AWS_IAM` auth; the signing name is `lambda`. + +**httpx_client.py** + +```python +import os + +import httpx + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +FUNCTION_URL = os.environ["PRICING_FUNCTION_URL"] # Lambda Function URL with AWS_IAM auth + +pricing = SigV4Signer(service="lambda") +client = httpx.Client(base_url=FUNCTION_URL, auth=pricing.httpx_auth(), timeout=5) + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + response = client.get("/quote", params={"sku": event["sku"], "qty": event["qty"]}) + response.raise_for_status() + return response.json() +``` + +### Sign only, send with any client + +`sign()` never touches the network. It returns a `SignedRequest` with the `method`, the `url` to send, the `headers` including `Authorization`, and the `body`. Use them with `urllib3`, a generated client, or anything else. + +**sign_only.py** + +```python +import json +import os + +import urllib3 + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +APPSYNC_URL = os.environ["APPSYNC_URL"] # AppSync GraphQL endpoint with IAM authorization + +appsync = SigV4Signer(service="appsync") +http = urllib3.PoolManager() + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + body = json.dumps({"query": "query { getOrder(id: $id) { status } }", "variables": {"id": event["order_id"]}}) + + # sign() never sends anything; use the signed URL, headers and body with any HTTP client + signed = appsync.sign("POST", APPSYNC_URL, headers={"content-type": "application/json"}, body=body) + response = http.request(signed.method, signed.url, headers=signed.headers, body=signed.body, timeout=5) + return json.loads(response.data) +``` + +> **Info: Send the URL you get back** + +The query string is re-encoded the way SigV4 canonicalises it (a space becomes `%20`, repeated keys are kept). Send `signed.url`, not the URL you passed in, or the signature will not match. The `requests` and `httpx` helpers do this for you. + +### Signing names + +The `service` parameter is the signing name of the target, not the hostname. Common ones: + +| Target | `service` | +| --- | --- | +| API Gateway REST and HTTP APIs | `execute-api` | +| Lambda Function URLs | `lambda` | +| AppSync | `appsync` | +| OpenSearch | `es` | +| Amazon S3 | `s3` | + +## Advanced + +### Amazon S3 + +Use `service="s3"`. The signer switches to the S3 canonical URI rules, so object keys with spaces, `+` or other characters that S3 encodes differently from the rest of AWS sign correctly, and the `x-amz-content-sha256` header is added. + +**s3_object.py** + +```python +import os +from urllib.parse import quote + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +BUCKET = os.environ["REPORTS_BUCKET"] + +# service="s3" applies the S3 canonical URI rules, so keys with spaces or "+" sign correctly +s3 = SigV4Signer(service="s3") + +def lambda_handler(event: dict, context: LambdaContext) -> str: + url = f"https://{BUCKET}.s3.{s3.region}.amazonaws.com/{quote(event['key'])}" + response = requests.get(url, auth=s3.requests_auth(), timeout=5) + response.raise_for_status() + return response.text +``` + +### Credentials and region outside Lambda + +Inside Lambda, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` are always set and the signer reads them. Elsewhere, pass `region=` and either `credentials=` (a `botocore.credentials.Credentials`) or `session=` (a `botocore.session.Session`, resolved through its provider chain). An explicit `credentials=` also serves cross-account calls with assumed-role credentials. + +**outside_lambda.py** + +```python +import botocore.session + +from aws_lambda_powertools.utilities.auth import SigV4Signer + +# Outside Lambda the environment variables may be missing; let botocore's provider chain +# find credentials (profile, SSO, instance role) and name the region explicitly. +signer = SigV4Signer( + service="execute-api", + region="eu-west-1", + session=botocore.session.get_session(), +) + +signed = signer.sign("GET", "https://abc123.execute-api.eu-west-1.amazonaws.com/prod/orders") +print(signed.headers["Authorization"]) +``` + +### SigV4a for multi-region endpoints + +`SigV4aSigner` produces an ECDSA signature valid across a set of regions, which S3 Multi-Region Access Points require. Pass the regions in `region_set`, or `"*"` for every region. It needs the `auth-sigv4a` extra. + +**sigv4a.py** + +```python +import os + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4aSigner +from aws_lambda_powertools.utilities.typing import LambdaContext + +MRAP_ALIAS = os.environ["MRAP_ALIAS"] # S3 Multi-Region Access Point alias + +# One ECDSA signature valid in both regions; needs pip install "aws-lambda-powertools[auth-sigv4a]" +s3_global = SigV4aSigner(service="s3", region_set=["us-east-1", "eu-west-1"]) + +def lambda_handler(event: dict, context: LambdaContext) -> str: + url = f"https://{MRAP_ALIAS}.accesspoint.s3-global.amazonaws.com/{event['key']}" + response = requests.get(url, auth=s3_global.requests_auth(), timeout=5) + response.raise_for_status() + return response.text +``` + +### Errors + +| Exception | When | +| --- | --- | +| `SignerConfigError` | At construction: no region, no credentials, an empty `service`, or `SigV4aSigner` without `awscrt`. The message says which, and never includes credential material. | +| `TypeError` | A streaming request body was passed to a client helper. Read it into `bytes` first; SigV4 hashes the whole payload. | + +A rejected signature comes back from the service as HTTP 403 with `The request signature we calculated does not match`. The usual causes are a wrong `service` name, a wrong `region`, or a client that changed the request after signing. diff --git a/.agents/skills/building-lambda-functions-with-powertools-python/references/installation.md b/.agents/skills/building-lambda-functions-with-powertools-python/references/installation.md index 90fba3b92aa..2c9cc704a40 100644 --- a/.agents/skills/building-lambda-functions-with-powertools-python/references/installation.md +++ b/.agents/skills/building-lambda-functions-with-powertools-python/references/installation.md @@ -40,8 +40,9 @@ Some features require additional dependencies. Install them as needed: | [Tracer](../core/tracer.md) | `pip install "aws-lambda-powertools[tracer]"` | `aws-xray-sdk` | | [Validation](../utilities/validation.md) | `pip install "aws-lambda-powertools[validation]"` | `fastjsonschema` | | [Parser](../utilities/parser.md) | `pip install "aws-lambda-powertools[parser]"` | `pydantic` | -| [JWT verification (alpha)](../utilities/auth.md) | `pip install "aws-lambda-powertools[jwt]"` | `PyJWT`, `cryptography`, `urllib3` | -| [OAuth2 client (alpha)](../utilities/oauth2.md) | `pip install "aws-lambda-powertools[oauth2]"` | `urllib3` | +| [JWT verification](../utilities/auth.md) | `pip install "aws-lambda-powertools[jwt]"` | `PyJWT`, `cryptography`, `urllib3` | +| [OAuth2 client](../utilities/oauth2.md) | `pip install "aws-lambda-powertools[oauth2]"` | `urllib3` | +| [Request signing](../utilities/signer.md) | nothing for SigV4, `pip install "aws-lambda-powertools[auth-sigv4a]"` for SigV4a | `botocore` from the runtime, `awscrt` for SigV4a | | [Data Masking](../utilities/data_masking.md) | `pip install "aws-lambda-powertools[datamasking]"` | `aws-encryption-sdk`, `jsonpath-ng` | | [Datadog Metrics](../core/metrics/datadog.md) | `pip install "aws-lambda-powertools[datadog]"` | `datadog-lambda` | | [Kafka (Avro)](../utilities/kafka.md) | `pip install "aws-lambda-powertools[kafka-consumer-avro]"` | `avro` | diff --git a/Makefile b/Makefile index 5460c8349de..a661f5f6800 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ dev: dev-quality-code uv run --locked pre-commit install dev-quality-code: - uv sync --locked --extra all --extra redis --extra datamasking --extra valkey + uv sync --locked --extra all --extra redis --extra datamasking --extra valkey --extra auth-sigv4a format-check: uv run --locked ruff format aws_lambda_powertools tests examples --check diff --git a/aws_lambda_powertools/utilities/auth/__init__.py b/aws_lambda_powertools/utilities/auth/__init__.py index decde3bff17..8b92fec11e9 100644 --- a/aws_lambda_powertools/utilities/auth/__init__.py +++ b/aws_lambda_powertools/utilities/auth/__init__.py @@ -10,8 +10,19 @@ from aws_lambda_powertools.utilities.auth.jwt import AuthErrorContext as AuthErrorContext from aws_lambda_powertools.utilities.auth.jwt import JWTVerifier as JWTVerifier from aws_lambda_powertools.utilities.auth.oauth2 import OAuth2Client as OAuth2Client + from aws_lambda_powertools.utilities.auth.signer import SignedRequest as SignedRequest + from aws_lambda_powertools.utilities.auth.signer import SigV4aSigner as SigV4aSigner + from aws_lambda_powertools.utilities.auth.signer import SigV4Signer as SigV4Signer -__all__ = ["AuthErrorContext", "AuthFailureReason", "JWTVerifier", "OAuth2Client"] +__all__ = [ + "AuthErrorContext", + "AuthFailureReason", + "JWTVerifier", + "OAuth2Client", + "SigV4Signer", + "SigV4aSigner", + "SignedRequest", +] def __getattr__(name: str) -> object: @@ -20,6 +31,9 @@ def __getattr__(name: str) -> object: "AuthFailureReason": "exceptions", "JWTVerifier": "jwt", "OAuth2Client": "oauth2", + "SigV4Signer": "signer", + "SigV4aSigner": "signer", + "SignedRequest": "signer", } if name in modules: value = getattr(importlib.import_module(f"{__name__}.{modules[name]}"), name) diff --git a/aws_lambda_powertools/utilities/auth/exceptions.py b/aws_lambda_powertools/utilities/auth/exceptions.py index e6f598183e4..2e22fe2a6a5 100644 --- a/aws_lambda_powertools/utilities/auth/exceptions.py +++ b/aws_lambda_powertools/utilities/auth/exceptions.py @@ -16,6 +16,7 @@ class AuthFailureReason(str, Enum): JWKS_UNAVAILABLE = "jwks_unavailable" TOKEN_EXCHANGE_FAILED = "token_exchange_failed" # nosec B105 DOWNSTREAM_REQUEST_FAILED = "downstream_request_failed" + SIGNER_MISCONFIGURED = "signer_misconfigured" class AuthError(Exception): diff --git a/aws_lambda_powertools/utilities/auth/signer/__init__.py b/aws_lambda_powertools/utilities/auth/signer/__init__.py new file mode 100644 index 00000000000..221232f66ee --- /dev/null +++ b/aws_lambda_powertools/utilities/auth/signer/__init__.py @@ -0,0 +1,26 @@ +"""AWS Signature Version 4 and 4A request signing.""" + +from __future__ import annotations + +import importlib +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.auth.signer.sigv4 import SignedRequest as SignedRequest + from aws_lambda_powertools.utilities.auth.signer.sigv4 import SigV4Signer as SigV4Signer + from aws_lambda_powertools.utilities.auth.signer.sigv4a import SigV4aSigner as SigV4aSigner + +__all__ = ["SigV4Signer", "SigV4aSigner", "SignedRequest"] + + +def __getattr__(name: str) -> object: + modules = {"SigV4Signer": "sigv4", "SignedRequest": "sigv4", "SigV4aSigner": "sigv4a"} + if name in modules: + value = getattr(importlib.import_module(f"{__name__}.{modules[name]}"), name) + globals()[name] = value + return value + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + +def __dir__() -> list[str]: + return sorted(set(globals()) | set(__all__)) diff --git a/aws_lambda_powertools/utilities/auth/signer/exceptions.py b/aws_lambda_powertools/utilities/auth/signer/exceptions.py new file mode 100644 index 00000000000..35032d1292d --- /dev/null +++ b/aws_lambda_powertools/utilities/auth/signer/exceptions.py @@ -0,0 +1,20 @@ +"""Errors raised by the request signer. Messages never include credential material.""" + +from aws_lambda_powertools.utilities.auth.exceptions import AuthError, AuthFailureReason + +__all__ = ["AuthError", "AuthFailureReason", "SignerConfigError"] + + +class SignerConfigError(AuthError): + """The signer cannot sign: no region, no credentials, or a missing optional dependency. + + Raised at construction, before any request is signed, so a misconfigured function + fails on the first cold start instead of sending unsigned requests. + """ + + message = "Request signer is not configured" + reason = AuthFailureReason.SIGNER_MISCONFIGURED + + def __init__(self, detail: str) -> None: + self.message = f"{SignerConfigError.message}: {detail}" + super().__init__() diff --git a/aws_lambda_powertools/utilities/auth/signer/sigv4.py b/aws_lambda_powertools/utilities/auth/signer/sigv4.py new file mode 100644 index 00000000000..c3e13e5c5c2 --- /dev/null +++ b/aws_lambda_powertools/utilities/auth/signer/sigv4.py @@ -0,0 +1,184 @@ +"""Sign HTTP requests to AWS services with Signature Version 4, using the botocore already in the Lambda runtime.""" + +from __future__ import annotations + +import os +from dataclasses import dataclass +from typing import TYPE_CHECKING, Any +from urllib.parse import parse_qsl, quote, urlsplit, urlunsplit + +from aws_lambda_powertools.utilities.auth.signer.exceptions import SignerConfigError + +if TYPE_CHECKING: + from collections.abc import Mapping + + from botocore.auth import BaseSigner + from botocore.credentials import Credentials + from botocore.session import Session + +__all__ = ["SigV4Signer", "SignedRequest"] + +_S3_SERVICES = frozenset({"s3", "s3-object-lambda", "s3express"}) + + +@dataclass(frozen=True) +class SignedRequest: + """A request with its signature headers added. Send it with any HTTP client.""" + + method: str + url: str + headers: dict[str, str] + body: bytes | None + + +class SigV4Signer: + """Sign HTTP requests with AWS Signature Version 4. + + Signing is separate from sending: ``sign()`` returns the signed headers and URL and never + touches the network. ``requests_auth()`` and ``httpx_auth()`` plug the same signing into + those clients so each request is signed on the way out. + + Region and credentials come from the Lambda environment by default. Pass ``credentials`` + or ``session`` to run outside Lambda or to call another account. + + Parameters + ---------- + service : str + Signing name of the target service, for example ``execute-api``, ``lambda``, ``appsync``, ``es`` or ``s3``. + region : str, optional + Region to sign for. Defaults to ``AWS_REGION``, then ``AWS_DEFAULT_REGION``. + credentials : botocore.credentials.Credentials, optional + Explicit credentials. Defaults to the ``AWS_ACCESS_KEY_ID``, ``AWS_SECRET_ACCESS_KEY`` and + ``AWS_SESSION_TOKEN`` environment variables that Lambda sets. + session : botocore.session.Session, optional + Resolve credentials through this session's provider chain instead of the environment. + + Example + ------- + >>> signer = SigV4Signer(service="execute-api") + >>> signed = signer.sign("GET", "https://abc123.execute-api.us-east-1.amazonaws.com/prod/orders") + >>> signed.headers["Authorization"].startswith("AWS4-HMAC-SHA256") + True + """ + + def __init__( + self, + service: str, + *, + region: str | None = None, + credentials: Credentials | None = None, + session: Session | None = None, + ) -> None: + if not service: + raise SignerConfigError("service is required, for example 'execute-api' or 'lambda'") + self.service = service + self.region = self._resolve_region(region) + self._credentials = self._resolve_credentials(credentials, session) + + def sign( + self, + method: str, + url: str, + headers: Mapping[str, str] | None = None, + body: str | bytes | None = None, + ) -> SignedRequest: + """Sign a request and return it with the signature headers added. No network call is made.""" + from botocore.awsrequest import AWSRequest + + payload = body.encode("utf-8") if isinstance(body, str) else body + url = _canonical_query(url) + request = AWSRequest(method=method.upper(), url=url, headers=dict(headers or {}), data=payload) + self._auth().add_auth(request) + return SignedRequest(method=method.upper(), url=url, headers=dict(request.headers), body=payload) + + def requests_auth(self) -> Any: + """Return an ``auth=`` object for the ``requests`` library that signs every request.""" + return _RequestsAuth(self) + + def httpx_auth(self) -> Any: + """Return an ``auth=`` object for the ``httpx`` library that signs every request.""" + return _HttpxAuth(self) + + def _auth(self) -> BaseSigner: + from botocore.auth import S3SigV4Auth, SigV4Auth + + auth_class = S3SigV4Auth if self.service in _S3_SERVICES else SigV4Auth + return auth_class(self._credentials, self.service, self.region) + + @staticmethod + def _resolve_region(region: str | None) -> str: + resolved = region or os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION") + if not resolved: + raise SignerConfigError("region could not be determined; pass region= or set AWS_REGION") + return resolved + + @staticmethod + def _resolve_credentials(credentials: Credentials | None, session: Session | None) -> Credentials: + if credentials is not None: + return credentials + if session is not None: + resolved = session.get_credentials() + if resolved is None: + raise SignerConfigError("the session has no credentials") + return resolved + + from botocore.credentials import Credentials + + access_key = os.getenv("AWS_ACCESS_KEY_ID") + secret_key = os.getenv("AWS_SECRET_ACCESS_KEY") + if not access_key or not secret_key: + raise SignerConfigError( + "no credentials in the environment; pass credentials= or session= when running outside Lambda", + ) + return Credentials(access_key, secret_key, os.getenv("AWS_SESSION_TOKEN") or None) + + +def _canonical_query(url: str) -> str: + """Re-encode the query string the way SigV4 canonicalises it, so what is signed is what is sent. + + HTTP clients encode a space as ``+`` and leave some characters bare; the service canonicalises + with ``%20`` and percent-encodes everything but unreserved characters, and the signatures would + not match. Repeated keys are kept. + """ + parts = urlsplit(url) + if not parts.query: + return url + pairs = parse_qsl(parts.query, keep_blank_values=True) + query = "&".join(f"{quote(key, safe='-_.~')}={quote(value, safe='-_.~')}" for key, value in pairs) + return urlunsplit((parts.scheme, parts.netloc, parts.path, query, parts.fragment)) + + +def _read_body(body: Any) -> bytes | None: + if body is None or isinstance(body, bytes): + return body + if isinstance(body, str): + return body.encode("utf-8") + raise TypeError("streaming request bodies cannot be signed; pass bytes or str") + + +class _RequestsAuth: + """Callable accepted by ``requests`` as ``auth=``; signs the prepared request in place.""" + + def __init__(self, signer: SigV4Signer) -> None: + self._signer = signer + + def __call__(self, request: Any) -> Any: + signed = self._signer.sign(request.method, request.url, dict(request.headers), _read_body(request.body)) + request.url = signed.url + request.headers.update(signed.headers) + return request + + +class _HttpxAuth: + """Callable accepted by ``httpx`` as ``auth=``; signs the request in place.""" + + def __init__(self, signer: SigV4Signer) -> None: + self._signer = signer + + def __call__(self, request: Any) -> Any: + signed = self._signer.sign(request.method, str(request.url), dict(request.headers), _read_body(request.content)) + if signed.url != str(request.url): + request.url = request.url.copy_with(query=urlsplit(signed.url).query.encode()) + for name, value in signed.headers.items(): + request.headers[name] = value + return request diff --git a/aws_lambda_powertools/utilities/auth/signer/sigv4a.py b/aws_lambda_powertools/utilities/auth/signer/sigv4a.py new file mode 100644 index 00000000000..082c4eb6609 --- /dev/null +++ b/aws_lambda_powertools/utilities/auth/signer/sigv4a.py @@ -0,0 +1,61 @@ +"""Sign HTTP requests with Signature Version 4A, valid across a set of regions. Needs the ``awscrt`` package.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from aws_lambda_powertools.utilities.auth.signer.exceptions import SignerConfigError +from aws_lambda_powertools.utilities.auth.signer.sigv4 import _S3_SERVICES, SigV4Signer + +if TYPE_CHECKING: + from collections.abc import Sequence + + from botocore.auth import BaseSigner + from botocore.credentials import Credentials + from botocore.session import Session + +__all__ = ["SigV4aSigner"] + + +class SigV4aSigner(SigV4Signer): + """Sign HTTP requests with AWS Signature Version 4A (ECDSA), for services that accept one + signature across several regions, such as S3 Multi-Region Access Points. + + Install the extra: ``pip install "aws-lambda-powertools[auth-sigv4a]"``. The Lambda runtime + does not ship ``awscrt``, so package it with your function. + + Parameters + ---------- + service : str + Signing name of the target service. + region_set : str | Sequence[str] + Regions the signature is valid for, for example ``["us-east-1", "eu-west-1"]``. ``"*"`` means every region. + credentials, session + Same as :class:`SigV4Signer`. + """ + + def __init__( + self, + service: str, + *, + region_set: str | Sequence[str] = "*", + credentials: Credentials | None = None, + session: Session | None = None, + ) -> None: + try: + import botocore.auth # noqa: F401 botocore wires the CRT signers only after its own auth module loads + import botocore.crt.auth # noqa: F401 + except ImportError as exc: + raise SignerConfigError( + "SigV4a needs the awscrt package; install aws-lambda-powertools[auth-sigv4a]", + ) from exc + self.region_set = region_set if isinstance(region_set, str) else ",".join(region_set) + if not self.region_set: + raise SignerConfigError("region_set cannot be empty; use '*' for every region") + super().__init__(service, region=self.region_set, credentials=credentials, session=session) + + def _auth(self) -> BaseSigner: + from botocore.crt.auth import CrtS3SigV4AsymAuth, CrtSigV4AsymAuth + + auth_class = CrtS3SigV4AsymAuth if self.service in _S3_SERVICES else CrtSigV4AsymAuth + return auth_class(self._credentials, self.service, self.region_set) diff --git a/docs/api_doc/auth.md b/docs/api_doc/auth.md index 9b89ff0e962..b9dc96c5d59 100644 --- a/docs/api_doc/auth.md +++ b/docs/api_doc/auth.md @@ -7,3 +7,6 @@ ::: aws_lambda_powertools.utilities.auth.jwt.testing ::: aws_lambda_powertools.utilities.auth.oauth2.client ::: aws_lambda_powertools.utilities.auth.oauth2.exceptions +::: aws_lambda_powertools.utilities.auth.signer.sigv4 +::: aws_lambda_powertools.utilities.auth.signer.sigv4a +::: aws_lambda_powertools.utilities.auth.signer.exceptions diff --git a/docs/getting-started/install.md b/docs/getting-started/install.md index 4db999fef32..a2d19186ab6 100644 --- a/docs/getting-started/install.md +++ b/docs/getting-started/install.md @@ -42,8 +42,9 @@ Some features require additional dependencies. Install them as needed: | [Tracer](../core/tracer.md) | `pip install "aws-lambda-powertools[tracer]"` | `aws-xray-sdk` | | [Validation](../utilities/validation.md) | `pip install "aws-lambda-powertools[validation]"` | `fastjsonschema` | | [Parser](../utilities/parser.md) | `pip install "aws-lambda-powertools[parser]"` | `pydantic` | -| [JWT verification (alpha)](../utilities/auth.md) | `pip install "aws-lambda-powertools[jwt]"` | `PyJWT`, `cryptography`, `urllib3` | -| [OAuth2 client (alpha)](../utilities/oauth2.md) | `pip install "aws-lambda-powertools[oauth2]"` | `urllib3` | +| [JWT verification](../utilities/auth.md) | `pip install "aws-lambda-powertools[jwt]"` | `PyJWT`, `cryptography`, `urllib3` | +| [OAuth2 client](../utilities/oauth2.md) | `pip install "aws-lambda-powertools[oauth2]"` | `urllib3` | +| [Request signing](../utilities/signer.md) | nothing for SigV4, `pip install "aws-lambda-powertools[auth-sigv4a]"` for SigV4a | `botocore` from the runtime, `awscrt` for SigV4a | | [Data Masking](../utilities/data_masking.md) | `pip install "aws-lambda-powertools[datamasking]"` | `aws-encryption-sdk`, `jsonpath-ng` | | [Datadog Metrics](../core/metrics/datadog.md) | `pip install "aws-lambda-powertools[datadog]"` | `datadog-lambda` | | [Kafka (Avro)](../utilities/kafka.md) | `pip install "aws-lambda-powertools[kafka-consumer-avro]"` | `avro` | diff --git a/docs/index.md b/docs/index.md index d8ece594d9c..be364106072 100644 --- a/docs/index.md +++ b/docs/index.md @@ -54,7 +54,7 @@ Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverles | [Metrics](./core/metrics/index.md) | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) | | [Event Handler](./core/event_handler/api_gateway.md) | Event handler for API Gateway, ALB, Lambda Function URL, VPC Lattice, AppSync, and Bedrock Agents | | [Parameters](./utilities/parameters.md) | Retrieve and cache parameter values from Parameter Store, Secrets Manager, AppConfig, or DynamoDB | -| [Auth (alpha)](./utilities/auth.md) | Verify JWT access tokens and [acquire client-credentials tokens](./utilities/oauth2.md) for downstream APIs | +| [Auth](./utilities/auth.md) | Verify JWT access tokens, [acquire client-credentials tokens](./utilities/oauth2.md) for downstream APIs, and [sign requests](./utilities/signer.md) to IAM-protected AWS endpoints | | [Parser](./utilities/parser.md) | Data parsing and deep validation using Pydantic | | [Batch Processing](./utilities/batch.md) | Handle partial failures for SQS, Kinesis Data Streams, and DynamoDB Streams | | [Idempotency](./utilities/idempotency.md) | Make your Lambda functions idempotent and prevent duplicate execution | diff --git a/docs/utilities/signer.md b/docs/utilities/signer.md new file mode 100644 index 00000000000..f47ed4785b8 --- /dev/null +++ b/docs/utilities/signer.md @@ -0,0 +1,125 @@ +--- +title: Request signing +description: Sign HTTP requests to AWS services with SigV4 and SigV4a +status: new +--- + + + +Sign HTTP requests to IAM-protected AWS endpoints with [Signature Version 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv4_signing.html){target="_blank"}, using the `botocore` the Lambda runtime already ships. Part of the Auth utility, next to [JWT verification](auth.md) and the [OAuth2 client](oauth2.md). + +## Key features + +* Sign a request and get back the headers and URL to send, with any HTTP client +* Drop-in `auth=` objects for `requests` and `httpx` that sign every call +* Region and credentials read from the Lambda environment, no credential provider chain on the cold start path +* S3 canonical rules applied when the service is S3 +* SigV4a for multi-region endpoints such as S3 Multi-Region Access Points, behind an optional extra + +## Getting started + +### Install + +Nothing to install for SigV4: the signer only needs `botocore`, which the Lambda runtime provides. If you package your function without the runtime's `boto3`, add `aws-lambda-powertools[aws-sdk]`. + +SigV4a needs the `awscrt` package, which the runtime does not ship: + +```bash +pip install "aws-lambda-powertools[auth-sigv4a]" +``` + +### Sign requests with `requests` + +Pass `requests_auth()` as `auth=` and every request through that session is signed on the way out. The example calls an API Gateway REST API with IAM authorization; the signing name for API Gateway is `execute-api`. + +=== "requests_client.py" + + ```python hl_lines="5 11 13 17" + --8<-- "examples/auth/signer/src/requests_client.py" + ``` + +### Sign requests with `httpx` + +`httpx_auth()` does the same for `httpx`. This example calls a Lambda Function URL with `AWS_IAM` auth; the signing name is `lambda`. + +=== "httpx_client.py" + + ```python hl_lines="5 10 11" + --8<-- "examples/auth/signer/src/httpx_client.py" + ``` + +### Sign only, send with any client + +`sign()` never touches the network. It returns a `SignedRequest` with the `method`, the `url` to send, the `headers` including `Authorization`, and the `body`. Use them with `urllib3`, a generated client, or anything else. + +=== "sign_only.py" + + ```python hl_lines="6 11 19 20" + --8<-- "examples/auth/signer/src/sign_only.py" + ``` + +!!! info "Send the URL you get back" + The query string is re-encoded the way SigV4 canonicalises it (a space becomes `%20`, repeated keys are kept). Send `signed.url`, not the URL you passed in, or the signature will not match. The `requests` and `httpx` helpers do this for you. + +### Signing names + +The `service` parameter is the signing name of the target, not the hostname. Common ones: + +| Target | `service` | +| --- | --- | +| API Gateway REST and HTTP APIs | `execute-api` | +| Lambda Function URLs | `lambda` | +| AppSync | `appsync` | +| OpenSearch | `es` | +| Amazon S3 | `s3` | + +## Advanced + +### Amazon S3 + +Use `service="s3"`. The signer switches to the S3 canonical URI rules, so object keys with spaces, `+` or other characters that S3 encodes differently from the rest of AWS sign correctly, and the `x-amz-content-sha256` header is added. + +=== "s3_object.py" + + ```python hl_lines="10 14 15" + --8<-- "examples/auth/signer/src/s3_object.py" + ``` + +### Credentials and region outside Lambda + +Inside Lambda, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` are always set and the signer reads them. Elsewhere, pass `region=` and either `credentials=` (a `botocore.credentials.Credentials`) or `session=` (a `botocore.session.Session`, resolved through its provider chain). An explicit `credentials=` also serves cross-account calls with assumed-role credentials. + +=== "outside_lambda.py" + + ```python hl_lines="7 8 9 10 11" + --8<-- "examples/auth/signer/src/outside_lambda.py" + ``` + +### SigV4a for multi-region endpoints + +`SigV4aSigner` produces an ECDSA signature valid across a set of regions, which S3 Multi-Region Access Points require. Pass the regions in `region_set`, or `"*"` for every region. It needs the `auth-sigv4a` extra. + +=== "sigv4a.py" + + ```python hl_lines="5 11 16" + --8<-- "examples/auth/signer/src/sigv4a.py" + ``` + +### Errors + +| Exception | When | +| --- | --- | +| `SignerConfigError` | At construction: no region, no credentials, an empty `service`, or `SigV4aSigner` without `awscrt`. The message says which, and never includes credential material. | +| `TypeError` | A streaming request body was passed to a client helper. Read it into `bytes` first; SigV4 hashes the whole payload. | + +A rejected signature comes back from the service as HTTP 403 with `The request signature we calculated does not match`. The usual causes are a wrong `service` name, a wrong `region`, or a client that changed the request after signing. + +## Testing your code + +Sign against fixed environment variables and assert on the headers that leave; the signature algorithm itself is botocore's and does not need testing on your side. + +=== "test_requests_client.py" + + ```python hl_lines="7 8 9 27 28" + --8<-- "examples/auth/signer/tests/test_requests_client.py" + ``` diff --git a/examples/auth/signer/src/httpx_client.py b/examples/auth/signer/src/httpx_client.py new file mode 100644 index 00000000000..e2d9a1b2310 --- /dev/null +++ b/examples/auth/signer/src/httpx_client.py @@ -0,0 +1,17 @@ +import os + +import httpx + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +FUNCTION_URL = os.environ["PRICING_FUNCTION_URL"] # Lambda Function URL with AWS_IAM auth + +pricing = SigV4Signer(service="lambda") +client = httpx.Client(base_url=FUNCTION_URL, auth=pricing.httpx_auth(), timeout=5) + + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + response = client.get("/quote", params={"sku": event["sku"], "qty": event["qty"]}) + response.raise_for_status() + return response.json() diff --git a/examples/auth/signer/src/outside_lambda.py b/examples/auth/signer/src/outside_lambda.py new file mode 100644 index 00000000000..b48e363a037 --- /dev/null +++ b/examples/auth/signer/src/outside_lambda.py @@ -0,0 +1,14 @@ +import botocore.session + +from aws_lambda_powertools.utilities.auth import SigV4Signer + +# Outside Lambda the environment variables may be missing; let botocore's provider chain +# find credentials (profile, SSO, instance role) and name the region explicitly. +signer = SigV4Signer( + service="execute-api", + region="eu-west-1", + session=botocore.session.get_session(), +) + +signed = signer.sign("GET", "https://abc123.execute-api.eu-west-1.amazonaws.com/prod/orders") +print(signed.headers["Authorization"]) diff --git a/examples/auth/signer/src/requests_client.py b/examples/auth/signer/src/requests_client.py new file mode 100644 index 00000000000..46bb805d17f --- /dev/null +++ b/examples/auth/signer/src/requests_client.py @@ -0,0 +1,19 @@ +import os + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +ORDERS_API = os.environ["ORDERS_API_URL"] # API Gateway REST API with IAM authorization + +# Region and credentials come from the Lambda execution environment +orders_api = SigV4Signer(service="execute-api") +http = requests.Session() +http.auth = orders_api.requests_auth() # every request through this session is signed + + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + response = http.post(f"{ORDERS_API}/orders", json={"customer_id": event["customer_id"]}, timeout=5) + response.raise_for_status() + return response.json() diff --git a/examples/auth/signer/src/s3_object.py b/examples/auth/signer/src/s3_object.py new file mode 100644 index 00000000000..e8b3a124b0a --- /dev/null +++ b/examples/auth/signer/src/s3_object.py @@ -0,0 +1,19 @@ +import os +from urllib.parse import quote + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +BUCKET = os.environ["REPORTS_BUCKET"] + +# service="s3" applies the S3 canonical URI rules, so keys with spaces or "+" sign correctly +s3 = SigV4Signer(service="s3") + + +def lambda_handler(event: dict, context: LambdaContext) -> str: + url = f"https://{BUCKET}.s3.{s3.region}.amazonaws.com/{quote(event['key'])}" + response = requests.get(url, auth=s3.requests_auth(), timeout=5) + response.raise_for_status() + return response.text diff --git a/examples/auth/signer/src/sign_only.py b/examples/auth/signer/src/sign_only.py new file mode 100644 index 00000000000..ab78abcc9ea --- /dev/null +++ b/examples/auth/signer/src/sign_only.py @@ -0,0 +1,21 @@ +import json +import os + +import urllib3 + +from aws_lambda_powertools.utilities.auth import SigV4Signer +from aws_lambda_powertools.utilities.typing import LambdaContext + +APPSYNC_URL = os.environ["APPSYNC_URL"] # AppSync GraphQL endpoint with IAM authorization + +appsync = SigV4Signer(service="appsync") +http = urllib3.PoolManager() + + +def lambda_handler(event: dict, context: LambdaContext) -> dict: + body = json.dumps({"query": "query { getOrder(id: $id) { status } }", "variables": {"id": event["order_id"]}}) + + # sign() never sends anything; use the signed URL, headers and body with any HTTP client + signed = appsync.sign("POST", APPSYNC_URL, headers={"content-type": "application/json"}, body=body) + response = http.request(signed.method, signed.url, headers=signed.headers, body=signed.body, timeout=5) + return json.loads(response.data) diff --git a/examples/auth/signer/src/sigv4a.py b/examples/auth/signer/src/sigv4a.py new file mode 100644 index 00000000000..82e27457543 --- /dev/null +++ b/examples/auth/signer/src/sigv4a.py @@ -0,0 +1,18 @@ +import os + +import requests + +from aws_lambda_powertools.utilities.auth import SigV4aSigner +from aws_lambda_powertools.utilities.typing import LambdaContext + +MRAP_ALIAS = os.environ["MRAP_ALIAS"] # S3 Multi-Region Access Point alias + +# One ECDSA signature valid in both regions; needs pip install "aws-lambda-powertools[auth-sigv4a]" +s3_global = SigV4aSigner(service="s3", region_set=["us-east-1", "eu-west-1"]) + + +def lambda_handler(event: dict, context: LambdaContext) -> str: + url = f"https://{MRAP_ALIAS}.accesspoint.s3-global.amazonaws.com/{event['key']}" + response = requests.get(url, auth=s3_global.requests_auth(), timeout=5) + response.raise_for_status() + return response.text diff --git a/examples/auth/signer/tests/test_requests_client.py b/examples/auth/signer/tests/test_requests_client.py new file mode 100644 index 00000000000..062fcb9eef4 --- /dev/null +++ b/examples/auth/signer/tests/test_requests_client.py @@ -0,0 +1,34 @@ +import json + +import requests + + +def test_orders_call_is_signed(monkeypatch): + # GIVEN the Lambda environment + monkeypatch.setenv("AWS_REGION", "us-east-1") + monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAEXAMPLE") + monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "example") # noqa: S105 test value + monkeypatch.setenv("ORDERS_API_URL", "https://abc123.execute-api.us-east-1.amazonaws.com/prod") + + from requests_client import http, lambda_handler + + sent = {} + + def fake_send(self, request, **kwargs): + sent["request"] = request + response = requests.Response() + response.status_code = 200 + response._content = json.dumps({"order_id": "o-1"}).encode() + return response + + monkeypatch.setattr(requests.Session, "send", fake_send) + + # WHEN the handler calls the API + assert lambda_handler({"customer_id": "c-9"}, {}) == {"order_id": "o-1"} + + # THEN the request left with a SigV4 signature over the JSON body + request = sent["request"] + assert request.headers["Authorization"].startswith("AWS4-HMAC-SHA256 Credential=AKIAEXAMPLE/") + assert "X-Amz-Date" in request.headers + assert json.loads(request.body) == {"customer_id": "c-9"} + assert http.auth is not None diff --git a/mkdocs.yml b/mkdocs.yml index b598d138c92..a54687b74a1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -33,9 +33,10 @@ nav: - core/event_handler/appsync_events.md - core/event_handler/bedrock_agents.md - utilities/parameters.md - - Auth (alpha): + - Auth: - JWT verification: utilities/auth.md - OAuth2 client: utilities/oauth2.md + - Request signing: utilities/signer.md - utilities/batch.md - utilities/kafka.md - utilities/typing.md diff --git a/noxfile.py b/noxfile.py index 8ac273ca7e0..756b7ed66a2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -289,3 +289,23 @@ def test_with_oauth2_required_packages(session: nox.Session): folders=[f"{PREFIX_TESTS_FUNCTIONAL}/auth/oauth2/"], extras="oauth2", ) + + +@nox.session() +def test_with_signer_required_packages(session: nox.Session): + """Verify SigV4 request signing with only botocore, the package the Lambda runtime already ships.""" + build_and_run_test( + session, + folders=[f"{PREFIX_TESTS_FUNCTIONAL}/auth/signer/"], + extras="aws-sdk", + ) + + +@nox.session() +def test_with_sigv4a_required_packages(session: nox.Session): + """Verify SigV4a request signing with the awscrt extra.""" + build_and_run_test( + session, + folders=[f"{PREFIX_TESTS_FUNCTIONAL}/auth/signer/"], + extras="aws-sdk,auth-sigv4a", + ) diff --git a/pyproject.toml b/pyproject.toml index 98442878b75..8a4c2ae6bda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,6 +91,9 @@ datamasking = [ kafka-consumer-avro = [ "avro (>=1.12.0,<2.0.0)", ] +auth-sigv4a = [ + "awscrt (>=0.23.0,<1.0.0)", +] kafka-consumer-protobuf = [ "protobuf (>=6.30.2,<8.0.0)", ] diff --git a/scripts/build_agent_skill_references.py b/scripts/build_agent_skill_references.py index 176a9bd3b1b..2ead603f9c2 100644 --- a/scripts/build_agent_skill_references.py +++ b/scripts/build_agent_skill_references.py @@ -34,7 +34,7 @@ "event-handler-appsync-events": ["core/event_handler/appsync_events.md"], "event-handler-bedrock-agents": ["core/event_handler/bedrock_agents.md"], "parameters": ["utilities/parameters.md"], - "auth-jwt-oauth2": ["utilities/auth.md", "utilities/oauth2.md"], + "auth-jwt-oauth2": ["utilities/auth.md", "utilities/oauth2.md", "utilities/signer.md"], "batch-processing": ["utilities/batch.md"], "kafka": ["utilities/kafka.md"], "typing": ["utilities/typing.md"], diff --git a/tests/functional/auth/signer/__init__.py b/tests/functional/auth/signer/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/auth/signer/conftest.py b/tests/functional/auth/signer/conftest.py new file mode 100644 index 00000000000..25deb1bafbe --- /dev/null +++ b/tests/functional/auth/signer/conftest.py @@ -0,0 +1,36 @@ +import datetime as dt + +import pytest + +FROZEN = dt.datetime(2026, 11, 15, 12, 0, 0, tzinfo=dt.timezone.utc) + + +@pytest.fixture +def lambda_env(monkeypatch): + """Credentials and region the way the Lambda runtime sets them.""" + monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAEXAMPLE") + monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "secretexample") # noqa: S105 test value + monkeypatch.setenv("AWS_SESSION_TOKEN", "tokenexample") # noqa: S105 test value + monkeypatch.setenv("AWS_REGION", "us-east-1") + monkeypatch.delenv("AWS_DEFAULT_REGION", raising=False) + + +@pytest.fixture +def frozen_clock(monkeypatch): + """Pin botocore's signing clock so signatures are reproducible.""" + import botocore.auth + + monkeypatch.setattr(botocore.auth, "get_current_datetime", lambda: FROZEN) + return FROZEN + + +def reference_signature(method, url, headers, body, service, region, *, s3=False): + """Sign with botocore directly, the way the AWS SDK does, to compare against the utility.""" + from botocore.auth import S3SigV4Auth, SigV4Auth + from botocore.awsrequest import AWSRequest + from botocore.credentials import Credentials + + request = AWSRequest(method=method, url=url, headers=dict(headers), data=body) + auth_class = S3SigV4Auth if s3 else SigV4Auth + auth_class(Credentials("AKIAEXAMPLE", "secretexample", "tokenexample"), service, region).add_auth(request) + return dict(request.headers) diff --git a/tests/functional/auth/signer/test_imports.py b/tests/functional/auth/signer/test_imports.py new file mode 100644 index 00000000000..3e4d1372d95 --- /dev/null +++ b/tests/functional/auth/signer/test_imports.py @@ -0,0 +1,23 @@ +"""Importing the signer must not load the JWT dependencies. botocore itself decides about urllib3 and awscrt.""" + +import subprocess +import sys + +PROBE = """ +import sys +from aws_lambda_powertools.utilities.auth import SigV4Signer, SignedRequest +loaded = {"jwt", "cryptography"} & set(sys.modules) +assert not loaded, loaded +import os +os.environ.update(AWS_ACCESS_KEY_ID="AKIAEXAMPLE", AWS_SECRET_ACCESS_KEY="x", AWS_REGION="us-east-1") +SigV4Signer(service="execute-api").sign("GET", "https://example.execute-api.us-east-1.amazonaws.com/") +loaded = {"jwt", "cryptography"} & set(sys.modules) +assert not loaded, loaded +print("ok") +""" + + +def test_signer_imports_only_botocore(): + result = subprocess.run([sys.executable, "-c", PROBE], capture_output=True, text=True, check=False) + assert result.returncode == 0, result.stderr + assert result.stdout.strip() == "ok" diff --git a/tests/functional/auth/signer/test_sigv4.py b/tests/functional/auth/signer/test_sigv4.py new file mode 100644 index 00000000000..8f024e421f8 --- /dev/null +++ b/tests/functional/auth/signer/test_sigv4.py @@ -0,0 +1,303 @@ +import pytest + +from aws_lambda_powertools.utilities.auth import SignedRequest, SigV4Signer +from aws_lambda_powertools.utilities.auth.signer.exceptions import SignerConfigError +from tests.functional.auth.signer.conftest import reference_signature + +API_URL = "https://abc123.execute-api.us-east-1.amazonaws.com/prod/orders" + + +def test_sign_adds_sigv4_headers_matching_the_sdk(lambda_env, frozen_clock): + # GIVEN a signer configured from the Lambda environment + signer = SigV4Signer(service="execute-api") + + # WHEN signing a request + signed = signer.sign("POST", API_URL, headers={"content-type": "application/json"}, body='{"id": "o-1"}') + + # THEN the result is a SignedRequest whose headers match what botocore itself produces + assert isinstance(signed, SignedRequest) + assert signed.method == "POST" and signed.url == API_URL and signed.body == b'{"id": "o-1"}' + expected = reference_signature( + "POST", + API_URL, + {"content-type": "application/json"}, + b'{"id": "o-1"}', + "execute-api", + "us-east-1", + ) + assert signed.headers["Authorization"] == expected["Authorization"] + assert signed.headers["Authorization"].startswith( + "AWS4-HMAC-SHA256 Credential=AKIAEXAMPLE/20261115/us-east-1/execute-api/aws4_request", + ) + assert signed.headers["X-Amz-Date"] == "20261115T120000Z" + assert signed.headers["X-Amz-Security-Token"] == "tokenexample" # noqa: S105 test value + assert signed.headers["content-type"] == "application/json" + + +def test_sign_keeps_repeated_query_parameters(lambda_env, frozen_clock): + # GIVEN a URL with a repeated query parameter + url = f"{API_URL}?status=open&status=paid&limit=5" + + # WHEN signing + signed = SigV4Signer(service="execute-api").sign("GET", url) + + # THEN both values stay in the URL and the signature is the one the SDK computes for them + assert signed.url == url + assert ( + signed.headers["Authorization"] + == reference_signature("GET", url, {}, None, "execute-api", "us-east-1")["Authorization"] + ) + + +def test_sign_accepts_str_bytes_and_empty_bodies(lambda_env, frozen_clock): + signer = SigV4Signer(service="lambda") + url = "https://fn.lambda-url.us-east-1.on.aws/" + + # GIVEN the same payload as str and as bytes + as_str = signer.sign("POST", url, body="hello") + as_bytes = signer.sign("POST", url, body=b"hello") + empty = signer.sign("GET", url) + + # THEN both sign identically and an empty body still signs + assert as_str.headers["Authorization"] == as_bytes.headers["Authorization"] + assert as_str.body == b"hello" + assert empty.body is None and empty.headers["Authorization"] + + +def test_s3_requests_follow_s3_canonical_rules(lambda_env, frozen_clock): + # GIVEN an S3 object key with characters S3 encodes differently from other services + url = "https://my-bucket.s3.us-east-1.amazonaws.com/reports/2026 11/summary+v2.csv" + + # WHEN signing for s3 + signed = SigV4Signer(service="s3").sign("GET", url) + + # THEN the payload hash header is present and the signature matches botocore's S3 signer, not the generic one + assert "X-Amz-Content-SHA256" in signed.headers + assert ( + signed.headers["Authorization"] + == reference_signature("GET", url, {}, None, "s3", "us-east-1", s3=True)["Authorization"] + ) + assert ( + signed.headers["Authorization"] != reference_signature("GET", url, {}, None, "s3", "us-east-1")["Authorization"] + ) + + +def test_explicit_region_wins_over_the_environment(lambda_env, frozen_clock): + signed = SigV4Signer(service="execute-api", region="eu-west-1").sign("GET", API_URL) + assert "/eu-west-1/execute-api/aws4_request" in signed.headers["Authorization"] + + +def test_region_falls_back_to_aws_default_region(lambda_env, monkeypatch): + monkeypatch.delenv("AWS_REGION") + monkeypatch.setenv("AWS_DEFAULT_REGION", "sa-east-1") + assert SigV4Signer(service="execute-api").region == "sa-east-1" + + +def test_missing_region_fails_at_construction(monkeypatch): + monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAEXAMPLE") + monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "secretexample") # noqa: S105 test value + monkeypatch.delenv("AWS_REGION", raising=False) + monkeypatch.delenv("AWS_DEFAULT_REGION", raising=False) + + with pytest.raises(SignerConfigError, match="region could not be determined"): + SigV4Signer(service="execute-api") + + +def test_missing_credentials_fail_at_construction(monkeypatch): + monkeypatch.setenv("AWS_REGION", "us-east-1") + for name in ("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"): + monkeypatch.delenv(name, raising=False) + + with pytest.raises(SignerConfigError, match="no credentials in the environment") as exc: + SigV4Signer(service="execute-api") + assert exc.value.reason.value == "signer_misconfigured" + assert "secret" not in str(exc.value).lower().replace("secret_access_key", "") + + +def test_explicit_credentials_are_used(monkeypatch, frozen_clock): + from botocore.credentials import Credentials + + for name in ("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"): + monkeypatch.delenv(name, raising=False) + + # GIVEN credentials passed explicitly, say for a cross-account call + signer = SigV4Signer(service="execute-api", region="us-east-1", credentials=Credentials("AKIAOTHER", "othersecret")) + signed = signer.sign("GET", API_URL) + + # THEN they sign the request and no session token header is added + assert "Credential=AKIAOTHER/" in signed.headers["Authorization"] + assert "X-Amz-Security-Token" not in signed.headers + + +def test_session_credentials_are_used(lambda_env, frozen_clock): + import botocore.session + + # GIVEN a botocore session (its provider chain reads the same environment here) + signer = SigV4Signer(service="execute-api", session=botocore.session.get_session()) + + # THEN the session's credentials sign the request + assert "Credential=AKIAEXAMPLE/" in signer.sign("GET", API_URL).headers["Authorization"] + + +def test_service_is_required(lambda_env): + with pytest.raises(SignerConfigError, match="service is required"): + SigV4Signer(service="") + + +def test_requests_auth_signs_the_prepared_request(lambda_env, frozen_clock): + requests = pytest.importorskip("requests") + + # GIVEN a requests call using the signer as auth + prepared = requests.Request( + "POST", + API_URL, + json={"id": "o-1"}, + auth=SigV4Signer(service="execute-api").requests_auth(), + ).prepare() + + # THEN the prepared request carries the signature computed over the headers requests sends + assert prepared.headers["Authorization"].startswith("AWS4-HMAC-SHA256") + expected = reference_signature( + "POST", + API_URL, + {k: v for k, v in prepared.headers.items() if k not in ("Authorization", "X-Amz-Date", "X-Amz-Security-Token")}, + prepared.body, + "execute-api", + "us-east-1", + ) + assert prepared.headers["Authorization"] == expected["Authorization"] + + +def test_httpx_auth_signs_the_request(lambda_env, frozen_clock): + httpx = pytest.importorskip("httpx") + + # GIVEN an httpx client using the signer as auth + signer = SigV4Signer(service="execute-api") + captured = {} + + def handler(request): + captured["headers"] = dict(request.headers) + return httpx.Response(200, json={"ok": True}) + + with httpx.Client(transport=httpx.MockTransport(handler), auth=signer.httpx_auth()) as client: + response = client.post(API_URL, json={"id": "o-1"}) + + # THEN the request went out signed + assert response.status_code == 200 + assert captured["headers"]["authorization"].startswith("AWS4-HMAC-SHA256") + assert captured["headers"]["x-amz-date"] == "20261115T120000Z" + + +def test_streaming_bodies_are_rejected(lambda_env): + import io + + class FakeRequest: + method = "POST" + url = API_URL + headers = {} + body = io.BytesIO(b"stream") + + with pytest.raises(TypeError, match="streaming request bodies"): + SigV4Signer(service="execute-api").requests_auth()(FakeRequest()) + + +def test_query_string_is_canonicalised_before_signing(lambda_env, frozen_clock): + # GIVEN a URL encoded the way HTTP clients do it: + for a space, bare characters, repeated keys + url = f"{API_URL}?q=a+b%26c&status=open&status=paid&blank=" + + # WHEN signing + signed = SigV4Signer(service="execute-api").sign("GET", url) + + # THEN the URL to send uses SigV4 encoding, keeps every pair, and the signature is computed over that URL + assert signed.url == f"{API_URL}?q=a%20b%26c&status=open&status=paid&blank=" + assert ( + signed.headers["Authorization"] + == reference_signature("GET", signed.url, {}, None, "execute-api", "us-east-1")["Authorization"] + ) + + +def test_requests_auth_sends_the_canonical_url(lambda_env, frozen_clock): + requests = pytest.importorskip("requests") + + # GIVEN requests encoding a space as + + prepared = requests.Request( + "GET", + API_URL, + params={"q": "a b"}, + auth=SigV4Signer(service="execute-api").requests_auth(), + ).prepare() + + # THEN the request that goes out carries the %20 form the signature was computed over + assert prepared.url == f"{API_URL}?q=a%20b" + assert ( + prepared.headers["Authorization"] + == reference_signature( + "GET", + prepared.url, + { + k: v + for k, v in prepared.headers.items() + if k not in ("Authorization", "X-Amz-Date", "X-Amz-Security-Token") + }, + None, + "execute-api", + "us-east-1", + )["Authorization"] + ) + + +def test_httpx_auth_sends_the_canonical_url(lambda_env, frozen_clock): + httpx = pytest.importorskip("httpx") + seen = {} + + def handler(request): + seen["url"] = str(request.url) + return httpx.Response(200) + + with httpx.Client( + transport=httpx.MockTransport(handler), + auth=SigV4Signer(service="execute-api").httpx_auth(), + ) as client: + client.get(API_URL, params=[("status", "open"), ("status", "paid"), ("q", "a b")]) + + assert seen["url"] == f"{API_URL}?status=open&status=paid&q=a%20b" + + +def test_session_without_credentials_fails_at_construction(lambda_env): + class EmptySession: + def get_credentials(self): + return None + + with pytest.raises(SignerConfigError, match="the session has no credentials"): + SigV4Signer(service="execute-api", session=EmptySession()) + + +def test_requests_auth_signs_a_text_body(lambda_env, frozen_clock): + requests = pytest.importorskip("requests") + + # GIVEN a form-style text body, which requests keeps as str + prepared = requests.Request( + "POST", + API_URL, + data="name=powertools", + auth=SigV4Signer(service="execute-api").requests_auth(), + ).prepare() + + # THEN it is signed over the encoded bytes of that text + expected = reference_signature( + "POST", + API_URL, + {k: v for k, v in prepared.headers.items() if k not in ("Authorization", "X-Amz-Date", "X-Amz-Security-Token")}, + b"name=powertools", + "execute-api", + "us-east-1", + ) + assert prepared.headers["Authorization"] == expected["Authorization"] + + +def test_signer_package_exposes_only_its_public_names(): + from aws_lambda_powertools.utilities.auth import signer + + assert {"SigV4Signer", "SigV4aSigner", "SignedRequest"} <= set(dir(signer)) + with pytest.raises(AttributeError, match="has no attribute 'unknown'"): + _ = signer.unknown diff --git a/tests/functional/auth/signer/test_sigv4a.py b/tests/functional/auth/signer/test_sigv4a.py new file mode 100644 index 00000000000..81a2ba918f8 --- /dev/null +++ b/tests/functional/auth/signer/test_sigv4a.py @@ -0,0 +1,47 @@ +import pytest + +from aws_lambda_powertools.utilities.auth.signer.exceptions import SignerConfigError + +awscrt = pytest.importorskip("awscrt", reason="SigV4a needs the auth-sigv4a extra") + + +def test_sigv4a_signs_for_a_region_set(lambda_env, frozen_clock): + from aws_lambda_powertools.utilities.auth import SigV4aSigner + + # GIVEN a SigV4a signer for two regions + signer = SigV4aSigner(service="s3", region_set=["us-east-1", "eu-west-1"]) + + # WHEN signing an S3 Multi-Region Access Point style request + signed = signer.sign("GET", "https://mrap-alias.accesspoint.s3-global.amazonaws.com/report.csv") + + # THEN the signature is ECDSA and names the region set + assert signed.headers["Authorization"].startswith("AWS4-ECDSA-P256-SHA256 Credential=AKIAEXAMPLE/") + assert signed.headers["X-Amz-Region-Set"] == "us-east-1,eu-west-1" + assert "x-amz-content-sha256" in {k.lower() for k in signed.headers} + + +def test_sigv4a_defaults_to_every_region(lambda_env, frozen_clock): + from aws_lambda_powertools.utilities.auth import SigV4aSigner + + signed = SigV4aSigner(service="execute-api").sign("GET", "https://abc.execute-api.us-east-1.amazonaws.com/p") + assert signed.headers["X-Amz-Region-Set"] == "*" + + +def test_sigv4a_rejects_an_empty_region_set(lambda_env): + from aws_lambda_powertools.utilities.auth import SigV4aSigner + + with pytest.raises(SignerConfigError, match="region_set cannot be empty"): + SigV4aSigner(service="execute-api", region_set=[]) + + +def test_sigv4a_without_awscrt_points_to_the_extra(lambda_env, monkeypatch): + import sys + + from aws_lambda_powertools.utilities.auth import SigV4aSigner + + # GIVEN an environment where botocore's CRT signers cannot be imported + monkeypatch.setitem(sys.modules, "botocore.crt.auth", None) + + # THEN construction fails with the install hint, before any request is signed + with pytest.raises(SignerConfigError, match=r"auth-sigv4a"): + SigV4aSigner(service="s3", region_set="*") diff --git a/uv.lock b/uv.lock index efe964cbf0b..97178fceb96 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 5 +revision = 3 requires-python = ">=3.10, <4.0.0" resolution-markers = [ "python_full_version >= '3.15'", @@ -311,6 +311,9 @@ all = [ { name = "pyjwt" }, { name = "urllib3" }, ] +auth-sigv4a = [ + { name = "awscrt" }, +] aws-sdk = [ { name = "boto3" }, ] @@ -412,6 +415,7 @@ requires-dist = [ { name = "aws-encryption-sdk", marker = "extra == 'datamasking'", specifier = ">=4.0.5,<5.0.0" }, { name = "aws-xray-sdk", marker = "extra == 'all'", specifier = ">=2.8.0,<3.0.0" }, { name = "aws-xray-sdk", marker = "extra == 'tracer'", specifier = ">=2.8.0,<3.0.0" }, + { name = "awscrt", marker = "extra == 'auth-sigv4a'", specifier = ">=0.23.0,<1.0.0" }, { name = "boto3", marker = "extra == 'aws-sdk'", specifier = ">=1.34.32,<2.0.0" }, { name = "cryptography", marker = "extra == 'all'", specifier = ">=50.0.1,<51.0.0" }, { name = "cryptography", marker = "extra == 'jwt'", specifier = ">=50.0.1,<51.0.0" }, @@ -434,7 +438,7 @@ requires-dist = [ { name = "urllib3", marker = "extra == 'oauth2'", specifier = ">=2.7.0,<3.0.0" }, { name = "valkey-glide", marker = "extra == 'valkey'", specifier = ">=1.3.5,<3.0" }, ] -provides-extras = ["parser", "validation", "tracer", "redis", "valkey", "jwt", "oauth2", "all", "aws-sdk", "datadog", "datamasking", "kafka-consumer-avro", "kafka-consumer-protobuf"] +provides-extras = ["parser", "validation", "tracer", "redis", "valkey", "jwt", "oauth2", "all", "aws-sdk", "datadog", "datamasking", "kafka-consumer-avro", "auth-sigv4a", "kafka-consumer-protobuf"] [package.metadata.requires-dev] dev = [ @@ -515,6 +519,50 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ef/c3/f30a7a63e664acc7c2545ca0491b6ce8264536e0e5cad3965f1d1b91e960/aws_xray_sdk-2.15.0-py2.py3-none-any.whl", hash = "sha256:422d62ad7d52e373eebb90b642eb1bb24657afe03b22a8df4a8b2e5108e278a3", size = 103228, upload-time = "2025-10-29T21:00:24.12Z" }, ] +[[package]] +name = "awscrt" +version = "0.38.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/39/be/56e6646fe5e866b4df5b8d92ee35dc0cbc0888871c5755f86c33a91960ea/awscrt-0.38.1.tar.gz", hash = "sha256:0dcebfaa70cf079133cd2352119e3d05e9b8ca1d1621736cfb54c03f3d5fef0f", size = 38435580, upload-time = "2026-11-04T10:15:23.853Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/95/57/15acefcc41730ec42f630a645bacf635c7aaabda9f2ca7e4d40c49512c6e/awscrt-0.38.1-cp310-cp310-macosx_10_15_universal2.whl", hash = "sha256:a4b54838ecbe2a3050ea9658770c9d7d3971ad1d02d0347c2dd2261ddf947666", size = 5251178, upload-time = "2026-11-04T10:13:58.956Z" }, + { url = "https://files.pythonhosted.org/packages/33/bb/5d67b894c089ebf83a9aaae67c1a22c0dba713cc85283e516a07fa7e4b7a/awscrt-0.38.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:47d3907b18db75bfe4ddfdb71d053150a570a7410ad2b68d30917b0849efdd05", size = 4185804, upload-time = "2026-11-04T10:14:00.581Z" }, + { url = "https://files.pythonhosted.org/packages/b4/cc/cd21b7c66e740152bada603176ba1fb579395f0d14de5a1701bc2cc521bf/awscrt-0.38.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0f1a02f6b38f6a303aeab37ce5058f3ff94f454f16ed412e382d116af2c703bd", size = 4456310, upload-time = "2026-11-04T10:14:02.035Z" }, + { url = "https://files.pythonhosted.org/packages/a9/24/5818ce5056dfd6e70c567970a71eaf048e55e6bb046b1edce9264e770f05/awscrt-0.38.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:44e661c1cfb34baab1b81f59192c0b99b9b76254a1f09127c30cf5d92ebcd719", size = 4106056, upload-time = "2026-11-04T10:14:03.887Z" }, + { url = "https://files.pythonhosted.org/packages/f6/37/45335e2e1debff559bb3f0d40bd6d61b46d322b1269cd0e7b4054263333d/awscrt-0.38.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:14e66dae194d7aa094fc8e1630d8636f7cccfac014af1b25733ce6ae9b67a8ce", size = 4327705, upload-time = "2026-11-04T10:14:06.858Z" }, + { url = "https://files.pythonhosted.org/packages/1c/98/24bff9af2e5b201cb4c093dbdcc59c3a0eb6277a874756b948323b8fff9a/awscrt-0.38.1-cp310-cp310-win32.whl", hash = "sha256:44e49e74a52626da40edf24ed85ee37ad8df6c739a72333e6677d4f3dbdd2276", size = 4307289, upload-time = "2026-11-04T10:14:08.62Z" }, + { url = "https://files.pythonhosted.org/packages/33/d0/299f99fc5d700461c0f00565db56662b079bef94ad2c8ab2ebdd2b0cea79/awscrt-0.38.1-cp310-cp310-win_amd64.whl", hash = "sha256:fcfaa9d1970941ae5502ebb35ee34a7b387b4eeb67c9cd4c6aae19c06ae01882", size = 4444808, upload-time = "2026-11-04T10:14:10.065Z" }, + { url = "https://files.pythonhosted.org/packages/9e/d6/475b72d3ea3e700e78a761f3eb7880cfec04fdb0b7f559da9bc49d803861/awscrt-0.38.1-cp311-abi3-macosx_10_15_universal2.whl", hash = "sha256:ea0b8c76d2cc365fc9c507efc69226fd51723669aa937f411bcd1d8881584e81", size = 5251160, upload-time = "2026-11-04T10:14:11.88Z" }, + { url = "https://files.pythonhosted.org/packages/26/5b/ee3e5a68ad2eb1cbcbdd5a1bcad5b5cc0d435a0b6f6d259412bf28307710/awscrt-0.38.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3c0378189c751f43a799c075e7ada06f46da28a8f7c2a65caae3de3dd16be405", size = 4144698, upload-time = "2026-11-04T10:14:13.588Z" }, + { url = "https://files.pythonhosted.org/packages/d5/e9/32e6a4473871790a81d52c21268db77a99390fd3c45c553e1cf185c593ea/awscrt-0.38.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:00de63a5a88d722cb7d515bbe35c1a723bd8d53a3bfcc2015bd57cc9ac6196b8", size = 4416887, upload-time = "2026-11-04T10:14:15.085Z" }, + { url = "https://files.pythonhosted.org/packages/a9/33/68e5def45ab0e6f487ec5e06bc7cb1de42914f77547e364a959c2d77bca6/awscrt-0.38.1-cp311-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a7d18bd0978bd3553172e3b7036c51ac6de6918b88f2be1cedc0abf74b5879b0", size = 4042198, upload-time = "2026-11-04T10:14:17.014Z" }, + { url = "https://files.pythonhosted.org/packages/c8/f8/ad73b4dc0a425aadcd46479dda276fe915a4c46e8ecac2c162ce92ec49df/awscrt-0.38.1-cp311-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:69a334a1eba5f94e7316c4e913ed0ea4a0322af77c4b9ea0862eebcdbbd31922", size = 4265493, upload-time = "2026-11-04T10:14:18.448Z" }, + { url = "https://files.pythonhosted.org/packages/80/16/67a1d62b95b25fbd58a6678078e1df08b6fc5806bc8e2d171dfb5d54d905/awscrt-0.38.1-cp311-abi3-win32.whl", hash = "sha256:53cbc33ef0001f8a2e688d4800ed96b08ae664331afbb00e3c07b43857b5b370", size = 4305128, upload-time = "2026-11-04T10:14:19.823Z" }, + { url = "https://files.pythonhosted.org/packages/40/e1/2d120762ad3d364c7504fb81c52b22fd95690da73bd8eb7caf06e53d79df/awscrt-0.38.1-cp311-abi3-win_amd64.whl", hash = "sha256:461289c2e87ee3365d8bf03ddcf7ae645ab7bfec2dd4e7d3f33b9f47491ce4e5", size = 4442254, upload-time = "2026-11-04T10:14:21.216Z" }, + { url = "https://files.pythonhosted.org/packages/db/d8/907ec17f579b9d1f295b08fdad46be65e8f9e676c3bdcbfdb1d9c25f7f81/awscrt-0.38.1-cp313-abi3-macosx_10_15_universal2.whl", hash = "sha256:1b1d9c5e581800ecab4cabf6c0530e8fcea4c81628884b551bcc246ccb50b56c", size = 5249442, upload-time = "2026-11-04T10:14:22.642Z" }, + { url = "https://files.pythonhosted.org/packages/64/24/91fe77fd1a39d3a7da78dad45ac34cb3472b733ccf7ef8893c356df8bae2/awscrt-0.38.1-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3718daa98190bd829ea403c5633bf1f97bbd76be32d7065182dd177013192143", size = 4135556, upload-time = "2026-11-04T10:14:24.141Z" }, + { url = "https://files.pythonhosted.org/packages/f8/f4/126c62ff3bededcdc249f23b74a0055931ab177189adfcabaa7fe83eb848/awscrt-0.38.1-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a6e9a262eb9c9386af02e72fecfe4883436fa7d0315b34fca22530fb1b793ac3", size = 4410659, upload-time = "2026-11-04T10:14:25.678Z" }, + { url = "https://files.pythonhosted.org/packages/da/75/22c73cede6c104798ec246f8b87fee13f97bcfbb078e56b3a98e584056e3/awscrt-0.38.1-cp313-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a1dddf2a0763049cba2b47a15d71e9fc738911544d3e1f846e930faf7c806d74", size = 4031299, upload-time = "2026-11-04T10:14:27.059Z" }, + { url = "https://files.pythonhosted.org/packages/8d/0d/8287c56e8fee638560c1046efd8f90dca9757d36dbe97cce6e571f546fbe/awscrt-0.38.1-cp313-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:a695b178ea279526587477906a2a9636177b048dcbe014d7962189b1525874bb", size = 4258215, upload-time = "2026-11-04T10:14:28.622Z" }, + { url = "https://files.pythonhosted.org/packages/78/d6/36e714d4967809c216a394f9270c6b891509256a714f05111abf07cfc76f/awscrt-0.38.1-cp313-abi3-win32.whl", hash = "sha256:644cb271d7d48cc7263b6e095a902779f97b62b0a2e2fd960a63d841c9f29e52", size = 4302117, upload-time = "2026-11-04T10:14:30.182Z" }, + { url = "https://files.pythonhosted.org/packages/76/ba/150a07209abe5de86e82347ebeef3fb25897e3609e1c8a64507d3ad35145/awscrt-0.38.1-cp313-abi3-win_amd64.whl", hash = "sha256:45748f4e41dde1329e9d58f9a2350152b912392d9a550a406170e2b85c47b6e2", size = 4439053, upload-time = "2026-11-04T10:14:31.474Z" }, + { url = "https://files.pythonhosted.org/packages/3d/26/71ba690eb7fc3d54ca9aa1661514106c5c0b73a8ec66e5d173ab017798af/awscrt-0.38.1-cp313-cp313t-macosx_10_15_universal2.whl", hash = "sha256:0ffc0765d70cf1d03576be2fd72cf16627563844d2b151db3fdb83a74fdb157d", size = 5259996, upload-time = "2026-11-04T10:14:33.302Z" }, + { url = "https://files.pythonhosted.org/packages/18/6a/6ad9fe01957be1aa7e84733a01dfbcb21d073924ff85bd92cf051a50742e/awscrt-0.38.1-cp313-cp313t-musllinux_1_1_aarch64.whl", hash = "sha256:9c0851ea7423c00216ad796fadd037ebc87cc17cd1192436395b457b8da83078", size = 4178203, upload-time = "2026-11-04T10:14:35.405Z" }, + { url = "https://files.pythonhosted.org/packages/72/46/5f8fd16d4d5fc17d324400ec2d0dad125df8b473ad6c628e2ac7491d7e69/awscrt-0.38.1-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:8590332d3e0cbec247ada7535fc1940a16761a9bf0e5a78c94826a453c47865f", size = 4397816, upload-time = "2026-11-04T10:14:37.154Z" }, + { url = "https://files.pythonhosted.org/packages/01/42/1efa05ed83ce06ac541e49422e21345759ec9876c580cd58834efc4820b3/awscrt-0.38.1-cp313-cp313t-win32.whl", hash = "sha256:6e43fe8df739d53e9752330e3cbbb25dd71d7fc8138f4c1131f42be866faf525", size = 4354445, upload-time = "2026-11-04T10:14:38.827Z" }, + { url = "https://files.pythonhosted.org/packages/db/e1/b105d7d3f04ca62146f1c3b319747e8eda2badab16eb19aea18f663d417e/awscrt-0.38.1-cp313-cp313t-win_amd64.whl", hash = "sha256:43901702ada2f521cb82398ccc75904c63fd74d9f41e5f618fe6000d73363038", size = 4488868, upload-time = "2026-11-04T10:14:40.98Z" }, + { url = "https://files.pythonhosted.org/packages/19/70/4332f2de622b4638668b45e819e7ffa8927b42e287e117f8933587b373d2/awscrt-0.38.1-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:19cab4bafb598b7489d90943f8fdfe9ffaf1d371a637b70e1d0059f3dba6ddbb", size = 5260021, upload-time = "2026-11-04T10:14:42.992Z" }, + { url = "https://files.pythonhosted.org/packages/18/bb/491a45d99445530b37bc04a20224dd6718d3c016d7e967e50ad7307b8535/awscrt-0.38.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:8df36a432bdd40a8b317e0149c650f221e782ee2ac04586eb885966d88a60212", size = 4265884, upload-time = "2026-11-04T10:14:44.545Z" }, + { url = "https://files.pythonhosted.org/packages/31/3c/07f37029b783025fbaad52316c491ff78072e96348579b29401603716611/awscrt-0.38.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f13ba8457f9665e9538ee61b4f0d91af76e41ac668e4b0c496dfc19d77284c3b", size = 4534429, upload-time = "2026-11-04T10:14:45.94Z" }, + { url = "https://files.pythonhosted.org/packages/26/cb/77740182c609c9327581e11c2362ccf929472705ee4354920ba370c9b76b/awscrt-0.38.1-cp314-cp314t-win32.whl", hash = "sha256:1541e05273d6397f94e656c3bfab14636c9b5355219cc30c6555f234bbcb9ffd", size = 4436966, upload-time = "2026-11-04T10:14:47.372Z" }, + { url = "https://files.pythonhosted.org/packages/8f/08/e7793a2a5ec086990970786ad5b6f903477456d775910a8a9d448d58d0a4/awscrt-0.38.1-cp314-cp314t-win_amd64.whl", hash = "sha256:20771e9b13d42b217789ee39705b8362614b6567b1cadaf53ce2d0ceac3d2a82", size = 4595481, upload-time = "2026-11-04T10:14:49.081Z" }, + { url = "https://files.pythonhosted.org/packages/e5/9f/a8c72ddd1865150aff3f758029b5c0a3db63abff65d21b1a9e4a9370a044/awscrt-0.38.1-cp315-abi3t-macosx_10_15_universal2.whl", hash = "sha256:2268dc65bdec3e2ea1e8987f154369f7e7a5edf6ab3292c6d5f24573133af266", size = 5250039, upload-time = "2026-11-04T10:14:50.702Z" }, + { url = "https://files.pythonhosted.org/packages/8b/59/03e688d778a11b4ab7dcbd8ff23c579d0f9ebeb35c99d8e075ec2b09d220/awscrt-0.38.1-cp315-abi3t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:24d197f4882a30d75c3ae2b3c90e00b43007499859985151d128753270a03dad", size = 4135499, upload-time = "2026-11-04T10:14:52.454Z" }, + { url = "https://files.pythonhosted.org/packages/d5/8c/5d11d4c9fdced42bf4a4ffb9e16c165165b05b4d947032178926b82d11d3/awscrt-0.38.1-cp315-abi3t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f6e93806099e0734d57d4fc92bcd29fb8a8850b1ddae0ceb0884e56734fedb72", size = 4411753, upload-time = "2026-11-04T10:14:54.229Z" }, + { url = "https://files.pythonhosted.org/packages/4b/af/adb2ef0009289eaf417dd847396f7ed249561aca783a4e32c0936088ed5d/awscrt-0.38.1-cp315-abi3t-win32.whl", hash = "sha256:15c470ca7741c81adaeee08ee963bd0ac84061ed6f2e4a21bf46a72e366c18f0", size = 4384650, upload-time = "2026-11-04T10:14:55.995Z" }, + { url = "https://files.pythonhosted.org/packages/24/40/1ff4cda4ccdf68ef58e02f9a7ff94cdf8fa72193f6e561cc1971639c8d1b/awscrt-0.38.1-cp315-abi3t-win_amd64.whl", hash = "sha256:af89483e9f00fa93b08567edc38a9cbf31934c4504e63b3f7a3f4d3c04cd10f5", size = 4541690, upload-time = "2026-11-04T10:14:57.498Z" }, +] + [[package]] name = "backports-asyncio-runner" version = "1.2.0"