From a7e198576c549234c0861d5f85d5e11f4027bebf Mon Sep 17 00:00:00 2001 From: ezekielelvis Date: Sun, 2 Aug 2026 11:48:10 +0000 Subject: [PATCH] fix: break circular CFN dependency in AuthStack post-confirmation trigger The post-confirmation Lambda's IAM policy referenced this.userPool.userPoolArn for the AdminAddUserToGroup grant, which combined with addTrigger() wiring the same function into the pool's LambdaConfig, formed a cycle CloudFormation rejected at changeset creation (Function -> Policy -> UserPool -> Function). Scoping the grant to a wildcard userpool/* ARN in this account/region drops the Policy -> UserPool edge and breaks the cycle; only one pool exists per stage so it's pool-scoped in practice. Confirmed first deploy to eu-west-1: Database/Notifications/Budget/Frontend created fine, Auth failed here. Co-Authored-By: Claude Sonnet 5 --- infrastructure/lib/stacks/auth-stack.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/infrastructure/lib/stacks/auth-stack.ts b/infrastructure/lib/stacks/auth-stack.ts index e4feb53..558c390 100644 --- a/infrastructure/lib/stacks/auth-stack.ts +++ b/infrastructure/lib/stacks/auth-stack.ts @@ -93,7 +93,14 @@ export class AuthStack extends Stack { postConfirmationFn.addToRolePolicy( new PolicyStatement({ actions: ['cognito-idp:AdminAddUserToGroup'], - resources: [this.userPool.userPoolArn], + // Scoped to any user pool in this account/region rather than + // `this.userPool.userPoolArn`: referencing the pool's own ARN + // here creates a circular CloudFormation dependency, since + // addTrigger() below also makes the pool depend on this + // function's ARN (the classic "post-confirmation trigger needs a + // permission on its own pool" cycle). Only one user pool exists + // per stage, so this is pool-scoped in practice. + resources: [`arn:${this.partition}:cognito-idp:${this.region}:${this.account}:userpool/*`], }), );