How does Lambda process SQS messages and handle partial failures?
AdvancedConceptContainers and Serverless
Answer
The event source mapping polls the queue with long polling and invokes your function with a batch (up to 10, or 10,000 with a batching window). If the function throws, the whole batch returns to the queue after the visibility timeout, causing reprocessing of successes. Enable ReportBatchItemFailures and return the failed IDs.
{"batchItemFailures":[{"itemIdentifier":"msg-id-3"}]}
Set visibility timeout to at least 6x the function timeout, configure a DLQ with maxReceiveCount, and use MaximumConcurrency on the mapping to protect downstreams.
More on Containers and Serverless
ECS vs EKS vs Fargate: what is the relationship?BeginnerWhat are ECS task definitions, tasks and services?BeginnerWhat are ECS capacity providers?IntermediateWhat is the difference between the ECS task role and the task execution role?IntermediateHow does `awsvpc` network mode work in ECS?IntermediateWhat deployment strategies does ECS support?Advanced