title: Cognito custom-message triggered lambda returns InvalidLambdaResponseException
body: <p>I've created a lambda and assigned it to cognito throw the UI as its custom-message lambda.
  Here is the code in typescript: </p>
  
  <pre><code>export const handler = async (event) =&gt; {
      const trigger = event.triggerSource
      const customMessage = cloneDeep(customMessages[trigger])
      if (customMessage) {
          try {
              // inject cognito values to custom message
              const codeParameter = event.request.codeParameter
              const usernameParameter = event.request.usernameParameter
              for (let key in customMessage) {
                  let text = customMessage[key]
                  if (codeParameter) {
                      customMessage[key] = text.replace(/{{codeParameter}}/g, codeParameter)
                  }
                  if (usernameParameter) {
                      customMessage[key] = text.replace(/{{usernameParameter}}/g, usernameParameter)
                  }
              }
              // load HTML template
              let htmlFile = readFileSync(templateFilePath, { encoding: 'utf8' })
              htmlFile = htmlFile.replace(/(\r\n|\n|\r)/gm, '')
              const template = handlebars.compile(htmlFile)
              const html = template(customMessage)
              event.emailMessage = html
              event.response.emailSubject = customMessage.title
          } catch (err) {
              logger.error(err)
              return event
          }
      }
      return event
  }
  </code></pre>
  
  <p>Basically it loads an html template file and injects the code-parameters and username.</p>
  
  <p>now the response our signup flow lambda returns is:</p>
  
  <pre><code>{
      "message": "InvalidLambdaResponseException",
      "details": "Unrecognizable lambda output"
  }
  </code></pre>
  
  <p>I event tried to copy paste AWS example:</p>
  
  <pre><code>exports.handler = (event, context, callback) =&gt; {
      //
      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);
  };
  </code></pre>
  
  <p>The response is the same.</p>
  
  <p>Any suggestions?
  Thanks</p>