Skip to content
Cloud Efficiency Hub

Recursive Lambda Function Invocation

The short version

Recursive invocation occurs when a Lambda function triggers itself directly or indirectly, often through an event source like SQS, SNS, or another Lambda.

Liam Greenamyre

Principal Product Manager (Technical - External Services) @ Amazon Web Services (AWS)

AWS service
AWS Lambda
Category
Compute
Reference
CER-0165
Type
Inefficient Configuration

Explanation

Why the waste happens and who it affects.

This loop can be unintentional - for example, when the function writes output to a queue it also consumes. Lambda recursive loop detection, on by default, stops loops through SQS, SNS, S3, EventBridge custom event buses and Lambda-to-Lambda calls after about 16 invocations in the same chain when a supported AWS SDK is used. Loops through other services (e.g., DynamoDB), functions on older SDKs, or functions set to allow recursive loops can still lead to runaway invocations, dramatically increasing cost with no business value.

Billing model

The pricing dimensions that drive this cost.

  • Billed per request and per millisecond of execution time
  • Recursive invocations amplify both request count and total execution duration

How to detect

6 checks to find it in your estate.

  • Review Lambda functions for high and sustained invocation rates with no matching business activity
  • Review event source and destination configurations for circular references (e.g., writing back to a triggering SQS queue)
  • Check CloudWatch Logs for repetitive invocation patterns with identical payloads
  • Correlate Lambda cost spikes with recent deployments or configuration changes
  • Assess if DLQs or concurrency limits are missing from functions with self-trigger patterns
  • Alarm on the RecursiveInvocationsDropped metric and review functions whose recursive loop detection is set to Allow

How to fix

6 ways to remove the waste.

  • Refactor logic to prevent self-invocation or recursive event loops
  • Avoid writing to the same queue or stream that triggers the function
  • Implement Dead Letter Queues to prevent retry loops
  • Cap concurrency with reserved concurrency (`ReservedConcurrentExecutions`), and separately limit retries with `MaximumRetryAttempts` (asynchronous invocations and stream sources) or `maxReceiveCount` (SQS)
  • Utilize anomaly detection software to flag unusual invocation or cost patterns
  • Monitor function triggers and outputs as part of deployment validation

Documentation

Vendor references for pricing and configuration.