Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(apigateway): an HTTP API's responses carry apigw-requestid, not x-amzn-requestid (#2393)

jeffreyhellerff86f37c7ce8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41226691..85c7ac78 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **API Gateway — an HTTP API's responses carry `apigw-requestid`, not a REST API's request ids** — a response from an HTTP API's route got `x-amzn-requestid` and `x-amz-request-id`; an HTTP API names its request id `apigw-requestid`, 16 base64 characters, which it now sends instead. REST APIs keep `x-amzn-requestid`. Contributed by @jeffreyheller.
- **Lambda — publishing on create or code update leaves `$LATEST` unpublished** — `CreateFunction` and `UpdateFunctionCode` with `Publish: true` overwrote `$LATEST`'s `Version` with the new version number. `ListVersionsByFunction` then listed that number twice and no `$LATEST`, `GetFunctionConfiguration` without a qualifier reported it, and invoking `$LATEST` set `AWS_LAMBDA_FUNCTION_VERSION` to it. `$LATEST` now stays `$LATEST`, as on AWS; the create and update responses are unchanged.
### Added
diff --git a/ministack/app.py b/ministack/app.py
index 27c854bf..b41f37f4 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -2056,7 +2056,10 @@ async def _handle_execute_api_request(
http_api_path = apigw_v2.decode_http_api_path(raw_path)
if http_api_path.startswith(prefix):
execute_path = http_api_path[len(prefix):]
- return await apigw_v2.handle_execute(api_id, stage, execute_path, method, headers, body, query_params)
+ status, resp_headers, resp_body = await apigw_v2.handle_execute(api_id, stage, execute_path, method, headers, body, query_params)
+ # An HTTP API names its request id apigw-requestid (16 base64 characters); x-amzn-requestid is a REST API's.
+ resp_headers.setdefault("apigw-requestid", base64.b64encode(os.urandom(11)).decode())
+ return status, resp_headers, resp_body
except Exception as e:
logger.exception("Error in execute-api dispatch: %s", e)
return 500, {"Content-Type": "application/json"}, json.dumps({"message": str(e)}).encode()
@@ -2402,6 +2405,8 @@ def _with_data_plane_headers(response, request_id: str, include_s3_id: bool = Fa
status, headers, body = response
if wildcard_cors and "Access-Control-Allow-Origin" not in headers:
headers["Access-Control-Allow-Origin"] = "*"
+ if "apigw-requestid" in headers:
+ return status, headers, body
# An API Gateway gateway response already carries the id it rendered.
request_id = headers.setdefault("x-amzn-requestid", request_id)
if include_s3_id:
diff --git a/tests/test_apigatewayv2.py b/tests/test_apigatewayv2.py
index 36c955a6..e2280848 100644
--- a/tests/test_apigatewayv2.py
+++ b/tests/test_apigatewayv2.py
@@ -1348,6 +1348,44 @@ def test_apigw_v2_event_omits_null_fields_when_absent(apigw, lam):
lam.delete_function(FunctionName=fname)
+def test_http_api_response_request_id_header(apigw, lam):
+ """AWS: observed 2026-09-07, us-east-1, an HTTP API's integration responses: apigw-requestid
+ (e.g. Ct26qjlpoAMEbVg=) and no x-amzn-requestid or x-amz-request-id. AWS Knowledge Center
+ "collect-api-gateway-extended-request-ids": HTTP API apigw-requestid, REST API x-amz-apigw-id."""
+ import re
+ import urllib.request as _urlreq
+ import uuid as _uuid
+
+ fname = f"intg-reqid-{_uuid.uuid4().hex[:8]}"
+ lam.create_function(
+ FunctionName=fname,
+ Runtime="python3.12",
+ Role=_LAMBDA_ROLE,
+ Handler="index.handler",
+ Code={"ZipFile": _make_zip("def handler(event, context):\n return {'statusCode': 200, 'body': 'ok'}\n")},
+ )
+ api_id = apigw.create_api(Name=f"reqid-api-{fname}", ProtocolType="HTTP")["ApiId"]
+ int_id = apigw.create_integration(
+ ApiId=api_id,
+ IntegrationType="AWS_PROXY",
+ IntegrationUri=f"arn:aws:lambda:us-east-1:000000000000:function:{fname}",
+ PayloadFormatVersion="2.0",
+ )["IntegrationId"]
+ apigw.create_route(ApiId=api_id, RouteKey="GET /reqid", Target=f"integrations/{int_id}")
+ apigw.create_stage(ApiId=api_id, StageName="$default")
+ try:
+ req = _urlreq.Request(f"http://{api_id}.execute-api.localhost:{_EXECUTE_PORT}/reqid")
+ req.add_header("Host", f"{api_id}.execute-api.localhost:{_EXECUTE_PORT}")
+ resp = _urlreq.urlopen(req)
+ assert resp.status == 200
+ assert re.fullmatch(r"[A-Za-z0-9+/]{15}=", resp.headers["apigw-requestid"])
+ assert resp.headers["x-amzn-requestid"] is None
+ assert resp.headers["x-amz-request-id"] is None
+ finally:
+ apigw.delete_api(ApiId=api_id)
+ lam.delete_function(FunctionName=fname)
+
+
def test_apigw_raw_query_string_percent_encoded(apigw, lam):
"""rawQueryString must stay percent-encoded like AWS: a space in a value comes
back as %20, not a literal space (which breaks lambda_http / http::Uri) — #1035."""