Skip to content

Commit 9109ab4

Browse files
committed
docs(idempotency): cleanup timeout section
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent 427d365 commit 9109ab4

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

docs/utilities/idempotency.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,29 +283,23 @@ Imagine the function runs successfully, but the client never receives the respon
283283

284284
### Lambda timeouts
285285

286-
???+ note
287-
This is automatically done when you decorate your Lambda handler with [@idempotent decorator](#idempotent-decorator).
288-
289-
To prevent against extended failed retries when a [Lambda function times out](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/){target="_blank"},
290-
Powertools for AWS Lambda (Python) calculates and includes the remaining invocation available time as part of the idempotency record.
291-
292-
???+ example
293-
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will execute the invocation again as if it was in the `EXPIRED` state (e.g, `expire_seconds` field elapsed).
294-
295-
This means that if an invocation expired during execution, it will be quickly executed again on the next retry.
286+
By default, we protect against [concurrent executions](#handling-concurrent-executions-with-the-same-payload) with the same payload using a locking mechanism. However, if your Lambda function times out before completing the first invocation it will only accept the same request when the [idempotency record expire](#expiring-idempotency-records).
296287

297-
???+ important
298-
If you are only using the [@idempotent_function decorator](#idempotent_function-decorator) to guard isolated parts of your code,
299-
you must use `register_lambda_context` available in the [idempotency config object](#customizing-the-default-behavior) to benefit from this protection.
300-
301-
Here is an example on how you register the Lambda context in your handler:
288+
To prevent extended failures, use **`register_lambda_context`** function from your idempotency config to calculate and include the remaining invocation time in your idempotency record.
302289

303290
=== "Registering the Lambda context"
304291

305-
```python hl_lines="11 20"
292+
> This is unnecessary for [`@idempotent` decorator](#idempotent-decorator), as it captures the Lambda context from your handler function.
293+
294+
```python title="working_with_lambda_timeout.py" hl_lines="11 20"
306295
--8<-- "examples/idempotency/src/working_with_lambda_timeout.py"
307296
```
308297

298+
???+ example "Mechanics"
299+
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will run the invocation again as if it was in the `EXPIRED` state.
300+
301+
This means that if an invocation expired during execution, it will be quickly executed again on the next retry.
302+
309303
### Handling exceptions
310304

311305
If you are using the `idempotent` decorator on your Lambda handler, any unhandled exceptions that are raised during the code execution will cause **the record in the persistence layer to be deleted**.

0 commit comments

Comments
 (0)