Ravindra BagaleCourses & study guides मराठी

Chapter 93: AWS Lambda and Serverless for DevOps

DevOps

93.5 Invocation patterns and retries

Story (fictional teaching scenario). At a fictional Surat delivery shop, Luis from Madrid expects every failed request to retry twice. Neha discovers that the rule depends on how the function was invoked.

Invocation patterns and retries
Invocation patterns and retries

Why

Wrong retry assumptions lose work or repeat payments. Learn the caller and delivery path first.

What

  • Synchronous invocation waits for a response. The direct caller decides whether to retry function errors.
  • Asynchronous invocation queues an event for later processing; acceptance is not completion. By default Lambda retries function errors twice.
  • Event source mapping is a Lambda-managed poller that reads from a queue or stream and invokes your function.
  • Batch is a group of records delivered together. Queue visibility/redrive and stream retry behaviour differ.

How

  1. Draw the complete delivery path.

  2. Identify who owns retries.

  3. Handle duplicates even when retries are not expected.

  4. Set a failure destination and monitor it in a future funded implementation.

Example 1: Direct call versus asynchronous acceptance

  1. Read the input and the code.
Direct: request -> handler -> error response
Async: submit -> accepted -> worker runs later
  1. Read the result.

Output (illustrative; not executed on AWS)

Direct caller: decides next attempt
Async function error default: original attempt + up to 2 retries
  1. What each part means: A synchronous error does not mean Lambda automatically retries the handler for you. For async, two retries means up to three total attempts for function errors by default. Throttling and system failures have separate queue/backoff behaviour; do not reduce all failures to the two-retry rule.

Example 2: Queue batch failure plan

  1. Read the input and the code.
{"Records":[{"messageId":"demo-1"},{"messageId":"demo-2"}]}
  1. Read the result.

Output (illustrative; not executed on AWS)

Batch processing plan: demo-1 succeeds; demo-2 fails
Configure partial batch failure handling when supported.
  1. What each part means: Each record has its own ID. Without a suitable partial-batch response, successful records may return along with a failed batch. SQS visibility timeout controls when a message becomes visible again; redrive policy controls movement to a dead-letter queue. A stream failure can block progress on its shard until resolved or expired.

Ravindra Bagale's Tip

Accepted is not completed. Track the final outcome.

Did you understand? Let us try it once more.