CustomMessage Lambda throwing error due to emailBody ( {####} )

Viewed 53

Context:
I am having one NodeJS app holding my Lambda trigger handlers of my Cognito UserPool. That app has multiple NodeJS client apps. I am having multiple ForgetPassword html templates (for emails) for each of my client apps.

Problem:
I am encountering a problem with CustomMessage Lambda for ForgetPassword trigger with one the client apps, where I am having the following error (copy/pasted from my Postman):

at 'emailBody' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}\\s*]*\\{####\\}[\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}\\s*]*

It is mentioned in AWS documentation (in here) that emailMessage must contain: {####}. For my email templates I did include that. But what's strange is that client app 1 works fine (the correct template get sent and the {####} get replaced by the code generated by Cognito), but client app 2 doesn't (It throws the error displayed above).

I also want you to highlight that: in the error, it is said that the template didn't respect the regex which should verify that the template has {####}, but the regex of the error does check for \{####\}. Why is that? the regex should be {. . .}*\{####\}{. . .} instead of {. . .}*\\{####\\}{. . .}.

Code:
CustomMessage ForgotPassword trigger handler:

module.exports.customMessageHandler = async (event, context, callback) => {
    // LOGIC IN HERE . . .

    if (event.triggerSource === "CustomMessage_ForgotPassword") {
         if (//check which app is it: app 1 or app 2 to choose the correct template) {
             let message = async readFile(path_to_right_template);

             event.response.emailMessage = message;
             event.response.emailSubject = 'Forgot password recovery';

             console.log(message).   // I log the html template to make sure that it holds the {####}, and it does!
         }
    }

    callback(null, event);
}

Email HTML Template

<div> . . . content </div>


<table border="0" cellpadding="0" cellspacing="0" class="html_block"
    role="presentation"
    style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;"
    width="100%">
    <tr>
        <td>
            <div align="center"
                style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;text-align:center;">
                <div class="our-class"
                    style="margin:0 auto; height:40px; width:120px; background-color:#c2daf2; padding-top:10px;border-radius: 10px;">
                    
                                {####}
                                
                </div>
            </div>
        </td>
    </tr>
</table>


<div>content . . .</div>

Thank you all for your assistance, please let me know if I am missing any information that could help debug this issue.

0 Answers
Related