Search code examples
aws-cloudformationamazon-cognitoaws-cdkamazon-cognito-triggers

AWS Cognito Lambda triggers not created with CDK


I can't understand why the Cognito Lambda triggers are not created. The lambdas are created, but the list of triggers in the AWS console is empty and I have to choose them manually.

const postConfirmationLambda = new NodejsFunction(
  this,
  'PostConfirmLambda',
  userPoolLambdasProps
);

const postAuthenticationLambda = new NodejsFunction(
  this,
  'PostAuthLambda',
  userPoolLambdasProps
);

usersTable.grantReadWriteData(postConfirmationLambda);
usersTable.grantReadWriteData(postAuthenticationLambda);

const userPool = new UserPool(this, 'UserPool', {
  removalPolicy: RemovalPolicy.DESTROY,
  lambdaTriggers: {
    postConfirmationLambda,
    postAuthenticationLambda,
  },
});

Full code

CloudFormation template


Solution

  • lambdaTriggers expects a UserPoolTriggers interface type: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.UserPoolTriggers.html

    It would look like this:

    const userPool = new UserPool(this, 'UserPool', {
      removalPolicy: RemovalPolicy.DESTROY,
      lambdaTriggers: {
        postConfirmation: postConfirmationLambda,
        postAuthentication: postAuthenticationLambda,
      },
    });