Interview Prep/AWS/ECS, EKS, ECR and Lambda

An SQS-triggered Lambda processes the same messages again and again, and some end up in the DLQ even though the code succeeded.

IntermediateTroubleshootingECS, EKS, ECR and Lambda
Answer

Likely causes → The queue's visibility timeout is shorter than the function timeout, so messages become visible again while they are still being processed. Or one failing record makes the whole batch retry, because partial batch responses are not enabled.

Diagnose →

aws sqs get-queue-attributes --queue-url <url> --attribute-names VisibilityTimeout RedrivePolicy
aws lambda get-function-configuration --function-name consumer --query Timeout
aws lambda list-event-source-mappings --function-name consumer --query 'EventSourceMappings[].[BatchSize,FunctionResponseTypes]'

Fix →

  1. Set the visibility timeout to at least 6× the function timeout (AWS guidance)
  2. Turn on ReportBatchItemFailures and return only the failed message IDs: aws lambda update-event-source-mapping --uuid <id> --function-response-types ReportBatchItemFailures
  3. Make handlers idempotent

Prevent → Use a standard SQS-Lambda module with these defaults, and alarm on DLQ depth above 0.

aws All AWS questions Roadmap: EKS, ECS & serverless on AWS

More on ECS, EKS, ECR and Lambda