1
votes

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.

2

2 Answers

2
votes

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

2
votes

If after doing everything, your custom email template doesn't show up then check the following: