title: Connection reset while sending data from AWS Lambda to SQS queue
body: <p>I'm using AWS SDK for Java in which I'm sending data from AWS Lambda to SQS.</p>
  
  <p>We are getting exception:</p>
  
  <pre><code>Caused by: java.net.SocketException: Connection reset
  at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
  at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
  at sun.security.ssl.OutputRecord.writeBuffer(OutputRecord.java:431)
  at sun.security.ssl.OutputRecord.write(OutputRecord.java:417)
  at sun.security.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:886)
  at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:857)
  at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
  at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124)
  at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:160)
  at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:113)
  at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:120)
  at org.apache.http.entity.StringEntity.writeTo(StringEntity.java:167)
  at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156)
  at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:160)
  at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238)
  at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doSendRequest(SdkHttpRequestExecutor.java:63)
  at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
  at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
  at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
  at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
  at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
  at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1236)
  at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code> List&lt;SendMessageBatchRequestEntry&gt; sqsList= new LinkedList&lt;SendMessageBatchRequestEntry&gt;();
      int batchId = 0; //To send a unique batchId for each msg in a batch
      for (Metadata metadata: metadataList) {
          String jsonString = new Gson().toJson(metadata);
          sqsList.add(new SendMessageBatchRequestEntry(batchId + "", jsonString));
          batchId++;
      }
      amazonSqs.sendMessageBatch(new SendMessageBatchRequest(queueUrl, sqsList));
  </code></pre>
  
  <p>Background what we are trying to do:</p>
  
  <p><em>We have a main Lambda function which create and initialize an SQS queue, and contain detail for every record that should be processed.
  Now SQS queue need to set up for creating batches of X number of messages from the queue and automatically invoke another SQS Lambda function for each of the batches.</em></p>