title: AWS Lambda not removing messages from the queue
body: <p>I am triggering a Lambda function from an SQS event with the following code:</p>
  
  <pre><code>@Override
  public Void handleRequest(SQSEvent sqsEvent, Context context) {
      for (SQSMessage sqsMessage : sqsEvent.getRecords()) {
          final String body = sqsMessage.getBody();
          try {
              //do stuff here
          } catch (Exception ex) {
              //send to DLQ
          }
      }
      return null;
  }
  </code></pre>
  
  <p>The "do stuff" is calling another Lambda function with the following code:</p>
  
  <pre><code>private final AWSLambda client;
      private final String functionName;
  
      public LambdaService(AWSLambdaAsync client, String functionName) {
          this.client = client;
          this.functionName = functionName;
      }
  
      public void runWithPayload(String payload) {
          logger.info("Invoking lambda {} with payload {}", functionName, payload);
          final InvokeRequest request = new InvokeRequest();
          request.withFunctionName(functionName).withPayload(payload);
          final InvokeResult invokeResult = client.invoke(request);
          final Integer statusCode = invokeResult.getStatusCode();
          logger.info("Invoked lambda {} with payload {}. Got status code {} and response payload {}",
                  functionName,
                  payload,
                  statusCode,
                  StandardCharsets.UTF_8.decode(invokeResult.getPayload()).toString());
          if(statusCode.equals(200) == false) {
              throw new IllegalStateException(String.format("There was an error executing the lambda function %s with payload %s", functionName, payload));
          }
      }
  
  </code></pre>
  
  <p>I am using the following libraries:</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-lambda-java-core&lt;/artifactId&gt;
    &lt;version&gt;1.2.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-lambda-java-events&lt;/artifactId&gt;
    &lt;version&gt;2.2.6&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-java-sdk-sqs&lt;/artifactId&gt;
    &lt;version&gt;1.11.505&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-java-sdk-lambda&lt;/artifactId&gt;
    &lt;version&gt;1.11.505&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>The problem is that it looks like the SQS message is not removed from the queue and it gets reprocessed over and over. It happens every 30 seconds which is exactly the value of <code>Default Visibility Timeout</code>. Now, as far as I know, if the lambda consuming the sqs messages is terminating properly it should automatically delete the message from the queue, but this is not happening.
  I don't think there is any error happening in the lambda because I am not getting any message in the DLQ (and I have a catch-all block) and I cannot see any stacktrace in the logs in Cloudwatch. I am bit confused about what's happening here, anyone has some good idea?</p>