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 →
- Set the visibility timeout to at least 6× the function timeout (AWS guidance)
- Turn on
ReportBatchItemFailuresand return only the failed message IDs:aws lambda update-event-source-mapping --uuid <id> --function-response-types ReportBatchItemFailures - Make handlers idempotent
Prevent → Use a standard SQS-Lambda module with these defaults, and alarm on DLQ depth above 0.
More on ECS, EKS, ECR and Lambda
`docker push 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4` fails with `no basic auth credentials` (or `denied: Your authorization token has expired. Reauthenticate and try again.`).BeginnerFargate tasks stop with `CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref ... dial tcp 52.x.x.x:443: i/o timeout`.Intermediate`ResourceInitializationError: unable to pull secrets or registry auth: ... AccessDeniedException: User: arn:aws:sts::111111111111:assumed-role/ecsTaskExecutionRole/... is not authorized to perform: secretsmanager:GetSecretValue`.IntermediateA task stops with `Essential container in task exited`, exit code 137, and reason `OutOfMemoryError: Container killed due to memory usage`.BeginnerThe ECS service event says `service api was unable to place a task because no container instance met all of its requirements. The closest matching container-instance ... has insufficient memory available.`IntermediateAn ECS deployment rolls back automatically, and the event says `deployment failed: tasks failed to start` from the circuit breaker.Advanced