Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito - Custom email message with Lambda trigger being overwritten

I'm using a lambda function to customize confirmation emails with AWS Cognito. My lambda function seems to work fine and looks like this:

exports.handler = async (event, context, callback) => {
  const sampleTemplate = `<html>
    <body>
      <div>${event.request.codeParameter}</div>
      <div>${event.userName}</div>
    </body>
  </html>`


  if (event.triggerSource === "CustomMessage_AdminCreateUser") {
    event.response.emailSubject = 'Lets hope this works'
    event.response.emailMessage = sampleTemplate

    console.log(event.response) // Logs look as expected
  }

  callback(null, event);
};

The problem is that when the emails arrive the message body is being overwritten by the content in the User Pools > Message Customizations tab. The subject line is working fine, but the email body is being overwritten. For example, the cognito settings look like this: enter image description here

And the emails look like this: enter image description here

As you can see, the lambda function worked for setting the email's subject line, but not the actual content. I can't find any setting to turn off that content and it can't be left blank... Any help is much appreciated.

like image 780
coops22 Avatar asked Aug 24 '26 14:08

coops22


1 Answers

For anyone finding this, I was able to find the answer. When using the CustomMessage_AdminCreateUser event, cognito will silently throw an error if you use event.userName in the template. Instead use event.request.usernameParameter and it will work

like image 167
coops22 Avatar answered Aug 27 '26 03:08

coops22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!