Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognito: Device Tracking Setting Resets After Adding Lambda Triggers for Cognito via CDK #33282

Open
1 task
cjnoname opened this issue Feb 4, 2025 · 0 comments
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@cjnoname
Copy link

cjnoname commented Feb 4, 2025

Describe the bug

When adding or modifying Lambda triggers for an Amazon Cognito User Pool using AWS CDK, the Device Tracking setting is unexpectedly reset. This requires manual reconfiguration after each deployment.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The Device Tracking setting should retain its configured value after adding or modifying Lambda triggers via AWS CDK.

Current Behavior

The Device Tracking setting is reset, requiring manual reconfiguration after each CDK deployment.

Reproduction Steps

The scripts we use:

  const customResourceLambdaName = `${lambdaName}-custom-resource`;
  const customResourceId = `CustomResourceCognito${generateResourceId(lambdaName)}`;

  lambda.addPermission("CognitoInvokePermission", {
    principal: new ServicePrincipal("cognito-idp.amazonaws.com"),
    action: "lambda:InvokeFunction",
    sourceArn: `arn:aws:cognito-idp:${stack.region}:${stack.account}:userpool/${cognitoUserPoolId}`
  });

  const updateUserPoolTrigger = new AwsCustomResource(stack, customResourceId, {
    functionName: customResourceLambdaName,
    role: new Role(stack, `${customResourceId}Role`, {
      roleName: `${customResourceLambdaName}-role`,
      assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
      inlinePolicies: {
        InlinePolicy: new PolicyDocument({
          statements: [
            new PolicyStatement({
              effect: Effect.ALLOW,
              actions: ["cognito-idp:UpdateUserPool"],
              resources: [
                `arn:aws:cognito-idp:${stack.region}:${stack.account}:userpool/${cognitoUserPoolId}`
              ]
            })
          ]
        })
      }
    }),
    onCreate: {
      service: "CognitoIdentityServiceProvider",
      action: "updateUserPool",
      parameters: {
        UserPoolId: cognitoUserPoolId,
        LambdaConfig: events
      },
      physicalResourceId: PhysicalResourceId.of(customResourceId)
    }
  });

  updateUserPoolTrigger.node.addDependency(lambda);

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.177.0

Framework Version

No response

Node.js Version

22.13.1

OS

MacOS 15.1.1

Language

TypeScript

Language Version

No response

Other information

No response

@cjnoname cjnoname added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 4, 2025
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant