# Recursive invocation loop between Lambda and SQS

Canonical: https://www.pointfive.co/efficiency-hub/inefficiencies/recursive-invocation-loop-between-lambda-and-sqs

When a Lambda function processes messages from an SQS queue but fails to handle certain messages properly, the same messages may be returned to the...

By: Christine Oji

Updated: 2026-09-28

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

# Recursive Invocation Loop Between Lambda and SQS

The short version

When a Lambda function processes messages from an SQS queue but fails to handle certain messages properly, the same messages may be returned to the queue and retried repeatedly.

Christine Oji

AWS service

[AWS Lambda](https://www.pointfive.co/efficiency-hub/cloud-services/aws-lambda)

Category

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

Reference

CER-0207

Type

Inefficient Architecture

## Explanation

Why the waste happens and who it affects.

In some cases, especially if the Lambda is also writing messages back to the same or a chained queue, this can create a recursive invocation loop. This loop results in high invocation counts, prolonged execution, and unnecessary costs, particularly if retries continue without a termination strategy.

Lambda recursive loop detection, on by default at no charge, stops a Lambda-SQS loop after about 16 invocations in the same chain of requests when the function uses a supported AWS SDK, and records it in the RecursiveInvocationsDropped metric. Loops still cost money until then, and SQS keeps retrying the message until maxReceiveCount is exceeded, so a redrive policy and DLQ on the source queue are still needed.

## Billing model

The pricing dimensions that drive this cost.

Billed based on the number of invocations and duration of execution time in milliseconds, rounded up to the nearest 1ms. Repeated or unintended invocations directly increase cost.

## How to detect

8 checks to find it in your estate.

- Sudden spike in Lambda invocations without corresponding increase in business traffic

- High volume of messages visible in an SQS queue without corresponding successful Lambda completions

- Lambda metrics showing consistent re-execution of the same payloads

- Lack of configured dead-letter queues or maximum receive count thresholds

- Application behavior where Lambda publishes messages back to the originating or an indirectly connected SQS queue

- Reprocessing patterns identifiable by message IDs or payload similarity in logs

- Account-wide cost variance alerts pointing to Lambda or SQS service anomalies

- Non-zero RecursiveInvocationsDropped metric, or functions whose recursive loop detection is set to Allow

## How to fix

5 ways to remove the waste.

- Introduce a  dead-letter queue (DLQ)  to route failed messages after a maximum number of retries

- Set a  maximumReceiveCount  on the SQS redrive policy to avoid indefinite reprocessing

- Refactor the Lambda logic to prevent re-enqueuing the same message unintentionally

- Monitor DLQ metrics and alarms to catch patterns before they become runaway costs

- Perform architecture reviews for recursive patterns in asynchronous messaging flows

## Documentation

Vendor references for pricing and configuration.

[Using AWS Lambda with Amazon SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html) 
[Amazon SQS Dead-Letter Queues](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html) 
[AWS Lambda Pricing](https://aws.amazon.com/lambda/pricing/)

## Related inefficiencies

[Browse the library](https://www.pointfive.co/efficiency-hub)

- AWS Lambda  CER-0296

### [Inefficient Lambda Pricing Model for Steady High-Volume Workloads (Use Lambda Managed Instances)](https://www.pointfive.co/efficiency-hub/inefficiencies/inefficient-lambda-pricing-for-steady-high-volume-workloads-use-lambda-managed-instances)

A function has steady, high-volume traffic (or predictable load) but continues running on default Lambda pricing, where costs scale with execution duration. Lambda Managed Instances runs Lambda on EC2 capacity managed by Lambda and...

Compute

- AWS Lambda  CER-0290

### [Unnecessary Lambda Provisioned Concurrency on Low-Utilization Functions](https://www.pointfive.co/efficiency-hub/inefficiencies/unnecessary-lambda-provisioned-concurrency-on-low-utilization-functions)

Provisioned Concurrency is enabled for Lambda functions that do not require consistently low latency or steady traffic. In such cases, provisioned concurrency remains allocated and billed during idle periods, creating ongoing cost without...

Compute

- AWS Lambda  CER-0209

### [Unnecessary Costs from Unused Lambda Versions with SnapStart](https://www.pointfive.co/efficiency-hub/inefficiencies/unnecessary-costs-from-unused-lambda-versions-with-snapstart)

Many teams publish new Lambda versions frequently (e.g., through CI/CD pipelines) but do not clean up old ones. When SnapStart is enabled on Python or .NET functions, each of these versions retains a cached snapshot, generating ongoing...

Compute

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

