3
votes

I would like to make a custom verification message for newly registered users in my AWS Cognito User Pool

To do so, I am trying to associate a Lamda function with a "Custom message" trigger.

However, I am not able to find the exact format of the custom message event, to be able to make my lambda function.

The lambda function that I came up with is

 exports.handler = function(event, context) {
    // 
    if(event.userPoolId === "us-east-t9....") {

        // Identify why was this function invoked
        if(event.triggerSource === "RegisterUser") {
            // This Lambda function was invoked because a new user signed up to the user-pool "theRequiredUserPool"
            // Ensure that your message contains event.request.codeParameter, this is the place holder for code that will be sent.
                        var link = "https://.....confirm_user.html?username="+ event.userName + "&code=" + event.request.codeParameter;
            var message = "Thank you for signing up. Your confirmation code is " + event.request.codeParameter;
            message+= " Click <a href='"+link+"'>here to finish your registatration!";
            event.response.emailSubject = "Welcome to the service";
            event.response.emailMessage = message;

        }
        // Create custom message for other events
    }
    // Customize messages for other user pools


    // Return result to Cognito
    context.done(null, event);
}

When I "test" my function in the Lambda console, it works, but that is because I am testing it against my own event object that I created, based on the only clue I could find in the documentation:

{  "version": 1,
  "triggerSource": "RegisterUser/ResendCode/ForgotPassword/VerifyUserAttribute",
  "region": "<region>",
  "userPoolId": "<userPoolId>",
  "userName": "<userName>",
  "callerContext": {
      "awsSdk": "<calling aws sdk with version>",
      "clientId": "<apps client id>",
      ...
  },
  "request": {
      "userAttributes": {
          "phone_verified": true/false,
          "email_verified": true/false,
          ... (all custom attributes)
      },
      "codeParameter": "{code}"
  },
  "response": {
      "smsMessage": "<custom message to be sent in the message with code parameter>"
      "emailMessage": "<custom message to be sent in the message with code parameter>"
      "emailSubject": "<custom email subject>"
  }
}

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

I need something more solid than that. I am not able to get my function to work and I don't know where to start. How can I implement a lambda function if I don't know what to expect in the event object? Is there any specification out there for the "Custom Message" event?

UPDATE: Now that Amazon User Pool's are out of beta, since July 29, 2016, I am no longer having this problem.

1
You could use console.log() to log the event attribute and check its structure in CloudWatch. Do you know if the lambda is even called? The "monitoring" tab in Lambda should help you to see that. - Alexis N-o
That's a good idea.@AlexisN-o And no, it doesn't look like the lambda is even called. :-( - Lioness

1 Answers

0
votes

Seems like there was an error in the previous documentation. Can you please try using triggerSource name as "CustomMessage_SignUp". You can also check the updated docs for the example.