Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(apigatewayv2): apiEndpoint follows the gateway's TLS scheme (#1893)
Jeff Heller99c51abb80c8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 952a40e3..194a2499 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]+### Fixed++- **API Gateway v2 — `apiEndpoint` follows the gateway's TLS scheme** — with `USE_SSL=1` the gateway listener serves only HTTPS, but CreateApi and the `AWS::ApiGatewayV2::Api` CloudFormation resource always returned an `http://` `apiEndpoint`, which nothing answers. They now return `https://`, or `wss://` for a WebSocket API, as AWS does. Without `USE_SSL` the endpoint keeps `http://`.+## [1.5.19] — 2026-09-30### Addeddiff --git a/ministack/services/apigateway.py b/ministack/services/apigateway.pyindex adcfc36e..b334425b 100644--- a/ministack/services/apigateway.py+++ b/ministack/services/apigateway.py@@ -1761,6 +1761,15 @@ def _resolve_custom_api_id(tags: dict, existing: "AccountRegionScopedDict") -> sreturn str(custom)+def _api_endpoint_scheme(protocol):+ """AWS's apiEndpoint scheme once the gateway serves TLS; http otherwise."""+ from ministack.core import tls as _tls++ if not _tls.use_ssl_enabled():+ return "http"+ return "wss" if protocol == "WEBSOCKET" else "https"++def _create_api(data):tags = data.get("tags", {})try:@@ -1777,7 +1786,7 @@ def _create_api(data):"apiId": api_id,"name": data.get("name", "unnamed"),"protocolType": protocol,- "apiEndpoint": f"http://{api_id}.execute-api.{_HOST}:{_PORT}",+ "apiEndpoint": f"{_api_endpoint_scheme(protocol)}://{api_id}.execute-api.{_HOST}:{_PORT}","createdDate": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),"routeSelectionExpression": data.get("routeSelectionExpression", default_rse),"apiKeySelectionExpression": data.get("apiKeySelectionExpression", "$request.header.x-api-key"),diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 136ea51c..f1ddbea5 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -9043,7 +9043,7 @@ def _apigw_v2_api_create(logical_id, props, stack_name):api = {"apiId": api_id,"protocolType": protocol,- "apiEndpoint": f"http://{api_id}.execute-api.{_MINISTACK_HOST}:{os.environ.get('GATEWAY_PORT', '4566')}",+ "apiEndpoint": f"{_apigw_v2._api_endpoint_scheme(protocol)}://{api_id}.execute-api.{_MINISTACK_HOST}:{os.environ.get('GATEWAY_PORT', '4566')}","createdDate": now_iso(),"tags": dict(props.get("Tags") or {}),**_apigw_v2_api_props(props, stack_name, logical_id),diff --git a/tests/test_apigatewayv2.py b/tests/test_apigatewayv2.pyindex 8275285a..67dccdfb 100644--- a/tests/test_apigatewayv2.py+++ b/tests/test_apigatewayv2.py@@ -2275,6 +2275,30 @@ def test_apigwv2_created_date_is_unix_timestamp(apigw):apigw.delete_api(ApiId=resp["ApiId"])[email protected]("use_ssl, http_scheme, ws_scheme", [("1", "https", "wss"), ("", "http", "http")])+def test_apigwv2_endpoint_scheme_follows_tls(monkeypatch, use_ssl, http_scheme, ws_scheme):+ """Under USE_SSL=1 the gateway serves only HTTPS, so apiEndpoint is https:// (wss:// for a WebSocket API), as on+ AWS; without it both keep http://."""+ monkeypatch.setenv("USE_SSL", use_ssl)+ for protocol, scheme in (("HTTP", http_scheme), ("WEBSOCKET", ws_scheme)):+ status, body = _payload(_apigw._create_api({"name": f"scheme-{protocol}", "protocolType": protocol}))+ assert status == 201+ assert body["apiEndpoint"].startswith(f"{scheme}://"), body["apiEndpoint"]+ _apigw._delete_api(body["apiId"])+++def test_apigwv2_cfn_api_endpoint_follows_tls(monkeypatch):+ """The AWS::ApiGatewayV2::Api provisioner builds the same apiEndpoint as CreateApi."""+ from ministack.services.cloudformation import provisioners++ monkeypatch.setenv("USE_SSL", "1")+ api_id, attrs = provisioners._apigw_v2_api_create("Api", {"Name": "cfn-tls", "ProtocolType": "WEBSOCKET"}, "stack")+ try:+ assert attrs["ApiEndpoint"].startswith("wss://"), attrs["ApiEndpoint"]+ finally:+ _apigw._delete_api(api_id)++# ========== from test_apigwv2_websocket.py =========="""API Gateway v2 WebSocket — end-to-end tests.