title: Testing async SQS sendMessage
body: <p>I have an async lambda, which performs an async SQS sendMessage request. The SQS queue is a standard queue, not FIFO, just to clarify.</p>
  
  <p>Here's an example of code (without irrelevant part of the logic):</p>
  
  <pre><code>exports.functionHandler = async (event, context, callback) =&gt; {
      try {
          let parsedBody = JSON.parse(event.Records[0].body);
          let modifiedBody = await doStuff(parsedBody);
  
          let sqsPayload = {
              MessageBody: JSON.stringify(modifiedBody),
              QueueUrl: my-queue-url
          };
  
          await sqs.sendMessage(sqsPayload).promise();
  
          callback(null, utils.respondSuccess("Done"));
      } catch (err) {
          // Handle error
  
          callback(null, utils.respondError(err));
      }
  };
  
  const doStuff = async payload =&gt; {
      // Do stuff 
  }
  </code></pre>
  
  <p>Pretty simple.</p>
  
  <p>Now the problem: I'm trying to test this function using the package <code>aws-sdk-mock</code>. This is how I was stubbing the sendMessage function when the lambda wasn't async and the sendMessage function was using the callback:</p>
  
  <pre><code>it("an awesome title for my test", async () =&gt; {
      let payload = {
          Records: [
              // Data here
          ]
      };
  
      AWS.mock("SQS", "sendMessage", (param, callback) =&gt; {
          let response = {
              ResponseMetadata: {
                  RequestId: "test-request-id"
              },
              MD5OfMessageBody: "a892e8d8589e97ca92fb70020f01c16c",
              MessageId: "test-message-id"
          };
  
          callback(null, response);
      });
  
      await app.functionHandler(payload, {}, (err, result) =&gt; {
          let parsedBody = JSON.parse(result.body);
          expect(parsedBody.message).to.be.equal("Done");
          // More stuff
      });
  
      AWS.restore();
  });
  </code></pre>
  
  <p>If I use this test, the sendMessage function throws the following error:</p>
  
  <pre><code>sendMessage returned an invalid MD5 response. Got "undefined", expecting "a892e8d8589e97ca92fb70020f01c16c".
  </code></pre>
  
  <p>I'm not sure how to test sendMessage asynchronously. I don't mind adopting a different package if it helps me to get the job done.</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks a lot</p>