0

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

MartinP
  • 365
  • 3
  • 12

1 Answers1

1

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,
  },
});
gshpychka
  • 8,523
  • 1
  • 11
  • 31
  • Thank you very much, sir. I wish UserPoolTriggers warned me, if it didn't allow any string for key. – MartinP Jul 21 '22 at 13:07