title: Aws SQS and Lambda Trigger - MultipleValidationErrors
body: <p>Hello guys I'm struggling to figure out why I keep getting <code>MultipleValidationErrors</code> for missing paramaters.</p>
  <p>Hopefully someone can figure this out, it's been driving me crazy today.</p>
  <p>Error:</p>
  <pre><code>&gt; {
  &gt;     &quot;errorType&quot;: &quot;MultipleValidationErrors&quot;,
  &gt;     &quot;errorMessage&quot;: &quot;There were 3 validation errors:\n* MissingRequiredParameter: Missing required key 'Source' in params\n*
  &gt; MissingRequiredParameter: Missing required key 'Data' in
  &gt; params.Message.Body.Html\n* MissingRequiredParameter: Missing required
  &gt; key 'Data' in params.Message.Subject&quot;,
  &gt;     &quot;code&quot;: &quot;MultipleValidationErrors&quot;,
  &gt;     &quot;message&quot;: &quot;There were 3 validation errors:\n* MissingRequiredParameter: Missing required key 'Source' in params\n*
  &gt; MissingRequiredParameter: Missing required key 'Data' in
  &gt; params.Message.Body.Html\n* MissingRequiredParameter: Missing required
  &gt; key 'Data' in params.Message.Subject&quot;,
  &gt;     &quot;errors&quot;: [
  &gt;         {
  &gt;             &quot;errorType&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;errorMessage&quot;: &quot;Missing required key 'Source' in params&quot;,
  &gt;             &quot;code&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;message&quot;: &quot;Missing required key 'Source' in params&quot;,
  &gt;             &quot;time&quot;: &quot;2022-04-22T14:31:01.177Z&quot;,
  &gt;             &quot;stack&quot;: [
  &gt;                 &quot;MissingRequiredParameter: Missing required key 'Source' in params&quot;,
  &gt;                 &quot;    at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:61:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)&quot;,
  &gt;                 &quot;    at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:132:42)&quot;,
  &gt;                 &quot;    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)&quot;,
  &gt;                 &quot;    at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:96:12)&quot;,
  &gt;                 &quot;    at /var/runtime/node_modules/aws-sdk/lib/event_listeners.js:86:9&quot;,
  &gt;                 &quot;    at finish (/var/runtime/node_modules/aws-sdk/lib/config.js:396:7)&quot;,
  &gt;                 &quot;    at /var/runtime/node_modules/aws-sdk/lib/config.js:414:9&quot;
  &gt;             ]
  &gt;         },
  &gt;         {
  &gt;             &quot;errorType&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;errorMessage&quot;: &quot;Missing required key 'Data' in params.Message.Body.Html&quot;,
  &gt;             &quot;code&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;message&quot;: &quot;Missing required key 'Data' in params.Message.Body.Html&quot;,
  &gt;             &quot;time&quot;: &quot;2022-04-22T14:31:01.177Z&quot;,
  &gt;             &quot;stack&quot;: [
  &gt;                 &quot;MissingRequiredParameter: Missing required key 'Data' in params.Message.Body.Html&quot;,
  &gt;                 &quot;    at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:61:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)&quot;
  &gt;             ]
  &gt;         },
  &gt;         {
  &gt;             &quot;errorType&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;errorMessage&quot;: &quot;Missing required key 'Data' in params.Message.Subject&quot;,
  &gt;             &quot;code&quot;: &quot;MissingRequiredParameter&quot;,
  &gt;             &quot;message&quot;: &quot;Missing required key 'Data' in params.Message.Subject&quot;,
  &gt;             &quot;time&quot;: &quot;2022-04-22T14:31:01.177Z&quot;,
  &gt;             &quot;stack&quot;: [
  &gt;                 &quot;MissingRequiredParameter: Missing required key 'Data' in params.Message.Subject&quot;,
  &gt;                 &quot;    at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:61:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)&quot;,
  &gt;                 &quot;    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)&quot;,
  &gt;                 &quot;    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)&quot;,
  &gt;                 &quot;    at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:132:42)&quot;,
  &gt;                 &quot;    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)&quot;
  &gt;             ]
  &gt;         }
  &gt;     ],
  &gt;     &quot;time&quot;: &quot;2022-04-22T14:31:01.177Z&quot;,
  &gt;     &quot;stack&quot;: [
  &gt;         &quot;MultipleValidationErrors: There were 3 validation errors:&quot;,
  &gt;         &quot;* MissingRequiredParameter: Missing required key 'Source' in params&quot;,
  &gt;         &quot;* MissingRequiredParameter: Missing required key 'Data' in params.Message.Body.Html&quot;,
  &gt;         &quot;* MissingRequiredParameter: Missing required key 'Data' in params.Message.Subject&quot;,
  &gt;         &quot;    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:40:28)&quot;,
  &gt;         &quot;    at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:132:42)&quot;,
  &gt;         &quot;    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)&quot;,
  &gt;         &quot;    at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:96:12)&quot;,
  &gt;         &quot;    at /var/runtime/node_modules/aws-sdk/lib/event_listeners.js:86:9&quot;,
  &gt;         &quot;    at finish (/var/runtime/node_modules/aws-sdk/lib/config.js:396:7)&quot;,
  &gt;         &quot;    at /var/runtime/node_modules/aws-sdk/lib/config.js:414:9&quot;,
  &gt;         &quot;    at Credentials.get (/var/runtime/node_modules/aws-sdk/lib/credentials.js:127:7)&quot;,
  &gt;         &quot;    at getAsyncCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:408:24)&quot;,
  &gt;         &quot;    at Config.getCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:428:9)&quot;
  &gt;     ] }
  </code></pre>
  <p>SQS send function:</p>
  <pre class="lang-js prettyprint-override"><code>     AwsSqsService.send('Request Password Reset', 'email', {
            'emailTo': {
              DataType: 'String',
              StringValue: email
            },
            'emailFrom': {
              DataType: 'String',
              StringValue: 'chris@example.co.uk'
            },
            'emailBody': {
              DataType: 'String',
              StringValue: '&lt;html&gt;&lt;p&gt;Testing Request&lt;/p&gt;&lt;/html&gt;'
            },
            'emailSubject': {
              DataType: 'String',
              StringValue: &quot;Testing Emails&quot;
            }
      });
  </code></pre>
  <p>SQS Code:</p>
  <pre class="lang-js prettyprint-override"><code>    export default class AwsSqsService {
        static accountId = '###########'
      
        public static send(messageBody: string = '', queue: string = '', messageAttributes: object = {}) {
          if (!messageBody) return false
          if (!queue) return false
      
          let queueToUse = ''
      
          switch (queue) {
            case 'email':
              queueToUse = Env.get('AWS_SQS_EMAILING_QUEUE')
              break
          }
      
          let sqs = new AWS.SQS({
            apiVersion: '2012-11-05',
            accessKeyId: Env.get('AWS_SQS_ACCESS_KEY'),
            secretAccessKey: Env.get('AWS_SQS_SECRET_KEY'),
            region: Env.get('AWS_SQS_REGION'),
          })
      
          let sqsParams = {
            MessageBody: messageBody,
            QueueUrl: `https://sqs.eu-west-2.amazonaws.com/${AwsSqsService.accountId}/${queueToUse}`,
          }
      
          /**
           * Example of Message Attribute
           *
           * recipient: {
           *    email: 'chris@heatable'
           * }
           *
           */
          if (messageAttributes) {
            sqsParams = {
              ...sqsParams,
              ...{
                MessageAttributes: messageAttributes,
              },
            }
          }
      
          sqs.sendMessage(sqsParams, function (err, data) {
            if (err) console.log(err, err.stack) // an error occurred
            else console.log(data) // successful response
          })
        }
      }
  </code></pre>
  <p>Lambda:</p>
  <pre class="lang-js prettyprint-override"><code>    let aws = require(&quot;aws-sdk&quot;);
      let ses = new aws.SES({ 
          region: 'eu-west-2',
          secretAccessKey: '########################',
          accessKeyId: '#########################'
      });
      
      exports.handler = async function (event) {
        const params = {
          Destination: {
            ToAddresses: [event[&quot;emailTo&quot;]],
          },
          Message: {
            Body: {
              Html: {
                  Data: event[&quot;emailBody&quot;]
              }
            },
      
            Subject: {
                Data: event[&quot;emailSubject&quot;],
            }
          },
          Source: event[&quot;emailFrom&quot;],
        };
       
        return ses.sendEmail(params).promise()
      };
  </code></pre>