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

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 →

  1. Set reserved concurrency to 0 right away to stop it: aws lambda put-function-concurrency --function-name thumbnailer --reserved-concurrent-executions 0
  2. Write output to a different bucket, or scope the trigger to the uploads/ prefix and write to thumbs/

Prevent → Keep recursion detection set to Terminate, use prefix or suffix filters on triggers, and set billing alarms on Lambda spend.

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

More on ECS, EKS, ECR and Lambda