1

My pre-signup-trigger lambda fails with the InvalidLambdaResponseException. Using nodejs. The user registration works without the trigger.

I tried pretty much all solutions suggested on SO how to handle this trigger. I have tried ending the lambda with context.done(null, event) and callback(null, event). The test script works. Worth mentioning that I have around 10 user attributes including 7 custom.

exports.handler = (event, context, callback) => {

// Check if business phone exists
event.response.autoConfirmEmail = false;
// This example uses a custom attribute "custom:domain"
if (event.request.userAttributes.hasOwnProperty("custom:business_phone")) {
    if ( event.request.userAttributes["custom:business_phone"] !== null
    && event.request.userAttributes["custom:business_phone"] !== "") {
        event.response.autoConfirmEmail = true;
    }
}

// Return to Amazon Cognito
callback(null, event);

//context.done(null, event);    
};

Test event works but user signup in browser returns InvalidLambdaResponseException. Tried one or both of the last two lines.

UPDATE: Getting same exception for Post confirm trigger. used aws doc example as is. Using runtime NodeJs 10.x. Tried 8.10 too.

To all he experts out there, please help!

jkeys
  • 3,803
  • 11
  • 39
  • 63
roadster
  • 51
  • 2
  • 8

1 Answers1

0

I had the same problem and it turned out the error was caused by another lambda that I had in my cloudformation:

exports.handler = (event, context, callback) => {
  if (event.triggerSource === "CustomMessage_ForgotPassword") {
    event.response.emailSubject = "Reset your password for blah";
    event.response.emailMessage = "Blah blah";
    callback(null, event);
  }
};

As signup sends an email, it was also executing the above lambda. But callback(null, event); was inside if statement and therefore not executed, since event.triggerSource was not "CustomMessage_ForgotPassword".

Fixing that by putting callback(null, event); outside of if statement solved the whole problem.

I'd suggest checking your other lambdas if they always execute callback(null, event) in the end, because error may be caused by a different lambda than you'd expect.

gullo
  • 1