MartinP
MartinP

Reputation: 407

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

Upvotes: 0

Views: 679

Answers (1)

gshpychka
gshpychka

Reputation: 11482

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,
  },
});

Upvotes: 1

Related Questions