AWS SQS to Lambda Failed Processed Messages



This content originally appeared on DEV Community and was authored by MacAndersonUche

Here’s a corrected version of your text:

Imagine a scenario where a Lambda function polls messages from an SQS queue but fails to process some messages.

Image description

Issue

During batch processing, SQS doesn’t track what happens after triggering Lambda. If a message fails or is throttled, it remains invisible until deleted or made visible again after the VisibilityTimeout expires. Throttled messages are treated as failures, and their ReceiveCount increases each time they’re retried. If a large number of messages arrives, some may be throttled and retried repeatedly until they reach the maxReceiveCount and are moved to the Dead Letter Queue (DLQ).

Fix

We implemented two solutions:

  1. maxReceiveCount: We increased the maxReceiveCount from 1 to 6 in the SQS queue. This was configured using CloudFormation:
   Queue:
     Type: AWS::SQS::Queue
     Properties:
       RedrivePolicy:
         maxReceiveCount: 6
  1. VisibilityTimeout: We increased the VisibilityTimeout from 40 to 120 seconds. This was done using CloudFormation:
   Queue:
     Type: AWS::SQS::Queue
     Properties:
       VisibilityTimeout: 120
       DelaySeconds: 30


This content originally appeared on DEV Community and was authored by MacAndersonUche