Member-only story

【Cognito】Cognito Custom Message Trigger is not working when I use the link verification type

Jangwook Kim
1 min readApr 27, 2022

If you are using cognito, we can customize sign up message using Custom Message Trigger.

According to documentation, you can customize your sign up email using this source code.

exports.handler = (event, context, callback) => {
//
if(event.userPoolId === "theSpecialUserPool") {
// Identify why was this function invoked
if(event.triggerSource === "CustomMessage_SignUp") {
// Ensure that your message contains event.request.codeParameter. This is the placeholder for code that will be sent
event.response.smsMessage = "Welcome to the service. Your confirmation code is " + event.request.codeParameter;
event.response.emailSubject = "Welcome to the service";
event.response.emailMessage = "Thank you for signing up. " + event.request.codeParameter + " is your verification code";
}
// Create custom message for other events
}
// Customize messages for other user pools
// Return to Amazon Cognito
callback(null, event);
};

As you can see, this code is for customization of Code verification type.

Although you are using Link verification type, it’s triggered when user sign up to your service. (You can check that into the Cloudwatch log group). But real email sent to user is not changed.

Your event.response.emailMessage contents are incorrect. That’s why email sent to user is not changed.

The value {####} is set into event.request.codeParameter, but you need to use the value like {##Verify Email##} to customize email for Link verify type.

If you change event.response.emailMessage like this, Custom Message Trigger will be working.

event.response.emailMessage = "Thank you for signing up. Please click {##this link##} to verify your email address.";

--

--

Jangwook Kim
Jangwook Kim

Written by Jangwook Kim

Korean, live in Japan. The programmer. I love to learn something new things. I’m publishing my toy projects using GitHub. Visit https://www.jangwook.net.

No responses yet