Kevin Danikowski
Kevin Danikowski

Reputation: 5196

Cognito Post confirmation being triggered multiple times

Saw this question on reddit and believe it should be brought over to stack overflow after having the same issue (https://www.reddit.com/r/aws/comments/bzvhu3/cognito_post_confirmation_being_triggered/)

For some reason, even though "triggerSource" is "PostConfirmation_ConfirmSignUp" both times for my cognito user pool sign up, it's getting run twice as seen in CloudWatch logs. The second time fails because the user has already been in the database, what is the issue?

Upvotes: 6

Views: 3338

Answers (2)

Udugam
Udugam

Reputation: 216

"Amazon Cognito invokes Lambda functions synchronously. When called, your Lambda function must respond within 5 seconds. If it does not, Amazon Cognito retries the call. After 3 unsuccessful attempts, the function times out. This 5-second timeout value cannot be changed"

Source: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#important-lambda-considerations

Upvotes: 12

Kevin Danikowski
Kevin Danikowski

Reputation: 5196

The issue is that your timeout setting is over 5 seconds, if it waits for 6 seconds, by the 5 second mark it will trigger again as if it fails.

Interesting Note: I had to bump my timeout to 10s because my stripe api was taking a while for some reason when I had 4s as the timeout it would often fail. After bumping to 10s timeout it no longer fails.... but it still averages a 2s execution time so it never runs twice. Not sure why this is, but it's good to be aware of.

Second note: I was unable to find documentation about this 5 second timeout retry, I did note it to be true though. If anyone has the location of this documentation please add it.

Upvotes: 7

Related Questions