# Recursive Lambda Function Invocation

Canonical: https://www.pointfive.co/efficiency-hub/inefficiencies/recursive-lambda-function-invocation

[Cloud Efficiency Hub](https://www.pointfive.co/efficiency-hub) 

# Recursive Lambda Function Invocation

## Explanation

Recursive invocation occurs when a Lambda function triggers itself directly or indirectly, often through an event source like SQS, SNS, or another Lambda. This loop can be unintentional - for example, when the function writes output to a queue it also consumes. Without controls, this can lead to runaway invocations, dramatically increasing cost with no business value.

## Relevant Billing Model

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

## Detection

- 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

## Remediation

- 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

- Set concurrency limits using \`ReservedConcurrency\` or \`MaximumRetryAttempts\`

- Utilize anomaly detection software to flag unusual invocation or cost patterns

- Monitor function triggers and outputs as part of deployment validation

## Relevant Documentation

[https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html) 
[https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html](https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html) 
[https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html\\#invocation-dlq](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq) 
[https://aws.amazon.com/lambda/pricing/](https://aws.amazon.com/lambda/pricing/)

[Submit Feedback](https://hub.pointfive.co/inefficiencies/recursive-lambda-function-invocation)

## At a glance

Reference

CER-0165

Cloud provider

AWS

Service

AWS Lambda

Category

[Compute](https://www.pointfive.co/efficiency-hub/service-category/compute)

Inefficiency type

Recursive Invocation Misconfiguration

## Contributed by

- Liam Greenamyre 

### Liam Greenamyre

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

[LinkedIn](https://www.linkedin.com/in/liam-greenamyre-01606310/)

---
Source: the public page above. Product screenshots and illustrative interfaces are examples, not live customer data.

