AWS Cognito - Custom email verification template

Let’s say you want to use the new awesome user management service provided by AWS. All nice and dandy, until you find that you can’t customize the email validation behaviour that much. I mean, yes, you can send HTML and you can add a custom domain, but that’s pretty much it. For example, I wanted to be able to redirect the user to my website after they validated their email and save the validatedAt timestamp in RDS.

I ended up using Cognito’s CustomMessage_SignUp event for altering the template and pointing the link to an API Gateway that did the actual validation, validatedAt save and the redirect.

In more detail, here’s the event handling. For the sake of simplicity this is not a valid HTML :)

The most important part is <div style="display: none">${linkParameter}</div>. Basically Cognito gives you this token that you need to add in your HTML and it will replace it with the validation URL that points to their hosted UI. Since that’s what I was aiming to avoid, I tried removing it all together but surprise, you can’t. You need to add it, even if it’s hidden, but it needs to be there. Another thing to keep in mind in the limitation for the emailMessage, you need to keep the text under 20000 characters, otherwise the email will not be sent.