title: How to mock AWS sqs call for unit testing
body: <p>I'm using AWS SQS queue in a Node application and I have to write the unit test cases for the same. For that, I want to mock the SQS function call <code>sendMessage()</code> in the test files so, what should I do?</p>
  
  <p>I have tried using <code>aws-sdk-mock</code> but while making the call to the <code>sendMessage()</code>, the function is trying to connect to the Queue URL.</p>
  
  <p><strong>Test File</strong></p>
  
  <pre><code>import AWSMock from 'aws-sdk-mock'
  import sendMessage from '../api/sqs/producer'
  
  describe.only('Test case for SQS SendMessage', () =&gt; {
    it('should return the UserEvent', async () =&gt; {
      AWSMock.mock('SQS', 'sendMessage', () =&gt; Promise.resolve('Success'))
      const res = await sendMessage('testURL', 'data')
      console.log('RES', res.response.data)
    })
  })
  </code></pre>
  
  <p><strong>Producer File</strong></p>
  
  <pre><code>const AWS = require('aws-sdk')
  
  const sqs = new AWS.SQS({
    region: 'us-east-1'
  })
  
  const sendMessage = async (msg, queueUrl) =&gt; {
    try {
      const params = {
        MessageBody: JSON.stringify(msg),
        QueueUrl: queueUrl
      }
      const res = await sqs.sendMessage(params).promise()
      return res
    } catch (err) {
      console.log('Error:', `failed to send message ${err}`)
      throw new Error(err)
    }
  }
  
  export { sendMessage as default }
  </code></pre>
  
  <p>In above code, I'm expecting the <code>Success</code> as a return value in <strong>res</strong></p>
  
  <p><strong>Output</strong></p>
  
  <pre class="lang-sh prettyprint-override"><code> FAIL  tests/sendMessage.test.js
    ● Console
  
      console.log api/sqs/producer/index.js:16
        Error: failed to send message UnknownEndpoint: Inaccessible host: `testurl'. This service may not b
  e available in the `us-east-1' region.
  
    ● Test case for SQS SendMessage › should return the UserEvent
  
      UnknownEndpoint: Inaccessible host: `testurl'. This service may not be available in the `us-east-1' r
  egion.
  </code></pre>