An S3-triggered Lambda bill exploded, and you get a notification that `Lambda stopped a recursive invocation loop`.
AdvancedTroubleshootingECS, EKS, ECR and Lambda
Answer
Likely causes → The function writes its output back into the same bucket and prefix that triggers it, so every write triggers the function again. Lambda recursive loop detection (for SQS, SNS, S3 and Lambda) stops it after about 16 iterations, but only for supported patterns.
Diagnose →
aws s3api get-bucket-notification-configuration --bucket images
aws lambda get-function-recursion-config --function-name thumbnailer
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name RecursiveInvocationsDropped \
--dimensions Name=FunctionName,Value=thumbnailer --statistics Sum --period 300 \
--start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)
Fix →
- Set reserved concurrency to 0 right away to stop it:
aws lambda put-function-concurrency --function-name thumbnailer --reserved-concurrent-executions 0 - Write output to a different bucket, or scope the trigger to the
uploads/prefix and write tothumbs/
Prevent → Keep recursion detection set to Terminate, use prefix or suffix filters on triggers, and set billing alarms on Lambda spend.
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