Skip to content

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

fix(cloudformation): ApiGatewayV2 Authorizer survives a property update (#1341)

ryan-bennett6de86889f9b6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7782bb1..cace2eee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
- **CloudFormation — resources unchanged by a stack update are left alone** — every previously-provisioned resource was reprocessed on every stack update regardless of whether its properties changed, and any resource type with no dedicated update handler fell back to calling create again — a fallback whose own name-generation regenerated a fresh random suffix on every call, and whose caller passed the wrong id into it, on top of that. An auto-named resource's "idempotent" create (the type framework's own documented expectation) silently produced a brand new, empty resource under a new identity on every single update, orphaning the real one — and anything referencing it via `Ref`/`Fn::GetAtt` picked up that new, wrong identity the moment it was reprocessed later in the same update, since real CloudFormation does propagate a changed reference. Found via a DynamoDB table silently duplicating on an unrelated update to a real multi-stack deploy. A genuinely unchanged resource is no longer touched at all, matching real CloudFormation; auto-generated names are now a deterministic hash of (stack name, logical id) rather than random, so the remaining case — a resource's properties *did* change but its type still has no update handler — reproduces the same name it started with. Also fixes the same symptom for `AWS::Events::EventBus` (previously failed a stack update outright with "already exists" once created) and any other resource type with no update handler and no name-collision guard of its own. Contributed by @ryan-bennett.
+- **CloudFormation — `AWS::ApiGatewayV2::Authorizer` survives a property update** — the type had no update handler, so changing e.g. `JwtConfiguration.Audience` (trusting an additional app client) fell back to create — whose `authorizerId` is a random id on every call, with no stable name to derive from — minting a second, orphaned authorizer while every `Route`'s own (unchanged) `AuthorizerId` kept pointing at the original, now-stale one. A real update handler now mutates the existing authorizer record in place, matching API Gateway's own `UpdateAuthorizer`. Contributed by @ryan-bennett.
- **CloudFormation — `AWS::SSM::Parameter::Value<...>` template parameters now resolve against SSM Parameter Store** — a template parameter typed `AWS::SSM::Parameter::Value<String>` (or `<List<String>>` / `<AWS::EC2::Image::Id>`) takes an SSM parameter *name* as its Default/provided value; real CloudFormation resolves that name against Parameter Store before `Ref` ever sees it — the mechanism behind, e.g., CDK's `StringParameter.valueForStringParameter`. MiniStack treated these like any other AWS-specific parameter type and passed the literal name straight through, so `Ref` returned the parameter's name instead of its stored value, and any resource property built from it (or a nested stack composing two independently-deployed stacks through a shared parameter) silently received the wrong string. Resolution now looks the name up in the SSM store at parameter-resolution time; a name that doesn't exist fails `CreateStack`/`UpdateStack` synchronously with a `ValidationError`, matching AWS. Contributed by @ryan-bennett.
## [1.4.15] — 2026-08-10
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 836224bc..9f1600f9 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -4755,6 +4755,42 @@ def _apigw_v2_authorizer_create(logical_id, props, stack_name):
return auth_id, {"AuthorizerId": auth_id}
+def _apigw_v2_authorizer_update(physical_id, old_props, new_props, stack_name):
+ """Mutates the existing authorizer record in place under its own
+ authorizerId — matching real API Gateway's UpdateAuthorizer, which
+ changes a property (e.g. jwtAudience, trusting an additional app
+ client) without reassigning the authorizer's id. Without this,
+ _update_resource's no-handler fallback landed on
+ _apigw_v2_authorizer_create, whose authorizerId is a fresh random
+ value on every call (there's no name to derive stability from, unlike
+ the resources _physical_name covers) — producing a second, orphaned
+ authorizer on every property change while every Route's own
+ AuthorizerId (unchanged, so Route itself was never reprocessed) kept
+ pointing at the original, now-stale one.
+ """
+ api_id = new_props.get("ApiId", "")
+ authorizers = _apigw_v2._authorizers.get(api_id, {})
+ authorizer = authorizers.get(physical_id)
+ if not authorizer:
+ return _apigw_v2_authorizer_create(physical_id, new_props, stack_name)
+ jwt_cfg = new_props.get("JwtConfiguration") or {}
+ authorizer.update({
+ "authorizerType": new_props.get("AuthorizerType", "JWT"),
+ "name": new_props.get("Name", authorizer["name"]),
+ "identitySource": new_props.get("IdentitySource", ["$request.header.Authorization"]),
+ "jwtConfiguration": {
+ "audience": jwt_cfg.get("Audience", []),
+ "issuer": jwt_cfg.get("Issuer", ""),
+ },
+ "authorizerUri": new_props.get("AuthorizerUri", ""),
+ "authorizerPayloadFormatVersion": new_props.get("AuthorizerPayloadFormatVersion", "2.0"),
+ "authorizerResultTtlInSeconds": new_props.get("AuthorizerResultTtlInSeconds", 300),
+ "enableSimpleResponses": new_props.get("EnableSimpleResponses", False),
+ "authorizerCredentialsArn": new_props.get("AuthorizerCredentialsArn", ""),
+ })
+ return physical_id, {"AuthorizerId": physical_id}
+
+
def _apigw_v2_authorizer_delete(physical_id, props):
api_id = props.get("ApiId", "")
authorizers = _apigw_v2._authorizers.get(api_id, {})
@@ -5600,7 +5636,7 @@ _RESOURCE_HANDLERS = {
"AWS::ApiGatewayV2::Stage": {"create": _apigw_v2_stage_create, "delete": _apigw_v2_stage_delete},
"AWS::ApiGatewayV2::Integration": {"create": _apigw_v2_integration_create, "delete": _apigw_v2_integration_delete},
"AWS::ApiGatewayV2::Route": {"create": _apigw_v2_route_create, "delete": _apigw_v2_route_delete},
- "AWS::ApiGatewayV2::Authorizer": {"create": _apigw_v2_authorizer_create, "delete": _apigw_v2_authorizer_delete},
+ "AWS::ApiGatewayV2::Authorizer": {"create": _apigw_v2_authorizer_create, "update": _apigw_v2_authorizer_update, "delete": _apigw_v2_authorizer_delete},
"AWS::SES::EmailIdentity": {"create": _ses_email_identity_create, "delete": _ses_email_identity_delete},
"AWS::WAFv2::WebACL": {"create": _waf_web_acl_create, "delete": _waf_web_acl_delete},
"AWS::CloudFront::CloudFrontOriginAccessIdentity": {
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index 67fedc4a..ac93b9fd 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -4678,6 +4678,58 @@ def test_cfn_apigwv2_authorizer_jwt(cfn, apigw):
_assert_apigwv2_api_not_found(lambda: apigw.get_authorizers(ApiId=api_id))
+def test_cfn_apigwv2_authorizer_update_trusts_additional_audience(cfn, apigw):
+ """Updating an Authorizer's JwtConfiguration (e.g. trusting an
+ additional app client's audience — hotshot's multi-app-support Phase B)
+ must mutate the same authorizer in place, not mint a second one.
+
+ Regression test: AWS::ApiGatewayV2::Authorizer had no update handler,
+ so a property change fell back to create — whose authorizerId is a
+ fresh random value every call (unlike name-based resources, there's no
+ stable identity to derive) — leaving a second, orphaned authorizer
+ while the Route's own (unchanged) AuthorizerId kept pointing at the
+ original, now-stale one with the old audience list."""
+ def template(audience):
+ return json.dumps({
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Resources": {
+ "HttpApi": {
+ "Type": "AWS::ApiGatewayV2::Api",
+ "Properties": {"Name": "cfn-apigwv2-authorizer-t02", "ProtocolType": "HTTP"},
+ },
+ "JwtAuthorizer": {
+ "Type": "AWS::ApiGatewayV2::Authorizer",
+ "Properties": {
+ "ApiId": {"Ref": "HttpApi"},
+ "Name": "cfn-apigwv2-authorizer-t02-jwt",
+ "AuthorizerType": "JWT",
+ "IdentitySource": ["$request.header.Authorization"],
+ "JwtConfiguration": {
+ "Audience": audience,
+ "Issuer": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_example",
+ },
+ },
+ },
+ },
+ })
+
+ stack_name = "cfn-apigwv2-authorizer-t02"
+ cfn.create_stack(StackName=stack_name, TemplateBody=template(["client-a"]))
+ _wait_stack(cfn, stack_name)
+ resources = cfn.describe_stack_resources(StackName=stack_name)["StackResources"]
+ api_id = [r for r in resources if r["ResourceType"] == "AWS::ApiGatewayV2::Api"][0]["PhysicalResourceId"]
+ authorizer_id_before = [r for r in resources if r["ResourceType"] == "AWS::ApiGatewayV2::Authorizer"][0]["PhysicalResourceId"]
+
+ cfn.update_stack(StackName=stack_name, TemplateBody=template(["client-a", "client-b"]))
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "UPDATE_COMPLETE"
+
+ authorizers = apigw.get_authorizers(ApiId=api_id)["Items"]
+ assert len(authorizers) == 1
+ assert authorizers[0]["AuthorizerId"] == authorizer_id_before
+ assert authorizers[0]["JwtConfiguration"]["Audience"] == ["client-a", "client-b"]
+
+
def test_cfn_apigwv2_integration_getatt(cfn, apigw):
"""Fn::GetAtt on IntegrationId resolves correctly."""
template = {