Submit feedback on
Recursive Invocation Loop Between Lambda and SQS
We've received your feedback.
Thanks for reaching out!
Oops! Something went wrong while submitting the form.
Close
Recursive Invocation Loop Between Lambda and SQS
Christine Oji
Service Category
Compute
Cloud Provider
AWS
Service Name
AWS Lambda
Inefficiency Type
Misconfigured Architecture
Explanation

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. 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.

Relevant Billing Model

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.

Detection
  • 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
Remediation
  • 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
Submit Feedback