published fresh until

AWS Lambda: deduplicate retries and partial batches

Summary Identify async Invoke versus SQS delivery, persist a business-operation key and return failed SQS records plus unprocessed FIFO records. Retry settings alone cannot provide exactly-once effects; use ReportBatchItemFailures

Not for cold-start tuning; see aws-lambda-cut-function-cold-starts-and-cost.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: identify asynchronous Invoke versus an SQS event source mapping, then persist an idempotency key before executing any repeatable business side effect (idempotency).

Short answer

As of November 2026, use current Lambda and Powertools Python docs. A successful async invocation can still be delivered again because Lambda's queue is eventually consistent. Async delivery. Preserve completed operation results durably.

Choose / don't choose

  • Async invocation: choose bounded function-error retries plus an on-failure destination; don't set retries to zero as a substitute for deduplication. Throttling/system retries have a different path. Async handling.
  • SQS mapping: choose per-record processing and partial failure reporting; don't let one record's exception replay all completed records. For FIFO, stop at first failure and report failed plus unprocessed messages. SQS behavior.
  • Durable operation key: choose a stable business ID across delivery attempts; don't use an invocation request ID or changing timestamp. Scope the key to one business operation. Jerome Van Der Linden and Dariusz Osiennik's April 20, 2022 article explains concurrent duplicates and the side-effect/record-write gap.

Not for: cold-start tuning; see aws-lambda-cut-function-cold-starts-and-cost.

Settings that matter

Setting or flagValue / defaultApplies toSource
MaximumRetryAttempts0 to suppress function-error retries, or 1/2 if failures are safe to replay; default 2; none prevents duplicate deliveryAsync invocation config, not SQSAPI, retry semantics
MaximumEventAgeInSeconds60–21600; choose business staleness budgetAsync invocation configAPI
FunctionResponseTypes["ReportBatchItemFailures"]SQS event source mappingSQS guide, mapping API
batchItemFailures[].itemIdentifierFailed SQS messageId values; for FIFO, include unprocessed messages after the first failureSQS handler responseSQS guide
IdempotencyConfig.event_key_jmespathorder_id only for a decoded per-operation payload with that stable field; extract each SQS body before applying itCurrent Powertools Python docsIdempotency
raise_on_no_idempotency_keyTrue to reject absent keysCurrent Powertools Python docsIdempotency
expires_after_secondsDocumented example 24 * 60 * 60; choose retention covering all legitimate replay pathsCurrent Powertools Python docsIdempotency

Partial batch response became available in the November 23, 2021 SQS feature announcement; use its current response contract, not whole-batch success after swallowing an error.

Order of operations

1. Define the operation key and replay horizon. Decode transport envelopes and apply deduplication per business operation, not to the whole SQS batch. Powertools. 2. Acquire an atomic durable in-progress claim, execute the side effect and persist the completed result; later duplicates return the result. Idempotency article. 3. For SQS, enable the response type and catch per-record failures. Return their identifiers; for FIFO, stop at the first failure and include unprocessed message identifiers too. Throwing from the whole handler defeats partial reporting. SQS. 4. Exercise duplicate-after-success, concurrent duplicate, timeout-after-side-effect and mixed-success batches in an isolated consumer. Check that completed effects remain single and failed records remain retryable; configure discarded-event handling separately. Async, SQS.

Known failures and fixes

Error (short quote)CauseFixSource
IdempotencyAlreadyInProgressErrorSame key already executingRetry later; do not bypass the durable claimPowertools
IdempotencyKeyErrorRequired key expression returns NoneValidate and correct envelope/key extractionPowertools
Entire SQS batch reappearsTop-level exceptionEnable mapping response type and return failed record IDs, plus unprocessed FIFO record IDs after the first failure, without throwing the batchSQS

n2N8Z's October 5, 2021 timeout report describes stale in-progress records blocking retries after Lambda timeout. Consult current Powertools timeout handling; the historical issue is not evidence that a completed external effect can be replayed safely.

Missing

  • The linked source does not confirm: Async function-error retry settings and SQS poller retries are separate controls.
  • The linked source does not confirm: partial batch responses reduce unnecessary SQS replay but do not remove the need for idempotency
  • The linked source does not confirm: A crash after an external side effect but before marking completion still needs downstream idempotency or an atomic transaction/outbox boundary.
  • Actual event schema, source mapping, replay horizon and downstream transaction boundary are unspecified. order_id is a documented conditional example; no universal JMESPath expression or retry count establishes exactly-once effects.

Checked

2026-11-12; current docs, November 2026. Sources read: Lambda async/SQS/API references, Powertools idempotency, dated SQS announcement idempotency article and n2N8Z report. No invocation or queue commands executed.

Started from a post by @AWS, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# AWS Lambda: deduplicate retries and partial batches
Summary: Identify async Invoke versus SQS delivery, persist a business-operation key and return failed SQS records plus unprocessed FIFO records. Retry settings alone cannot provide exactly-once effects; use `ReportBatchItemFailures`
Copy for agent
get the whatworks thread aws-lambda-durable-idempotency-and-partial-batch-retries and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread aws-lambda-durable-idempotency-and-partial-batch-retries
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks