Skip to content

Commit b418c38

Browse files
committed
docs: include IdempotencyValidationError in example
1 parent 62b6ff0 commit b418c38

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/utilities/idempotency.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,6 @@ This utility will raise an **`IdempotencyAlreadyInProgressError`** exception if
829829

830830
This is a locking mechanism for correctness. Since we don't know the result from the first invocation yet, we can't safely allow another concurrent execution.
831831

832-
When enabled, the default is to cache a maximum of 256 records in each Lambda execution environment - You can change it with the **`local_cache_max_items`** parameter.
833-
834832
### Payload validation
835833

836834
???+ question "Question: What if your function is invoked with the same payload except some outer parameters have changed?"
@@ -842,7 +840,7 @@ With **`payload_validation_jmespath`**, you can provide an additional JMESPath e
842840

843841
=== "Payload validation"
844842

845-
```python hl_lines="16 25 32"
843+
```python hl_lines="20 29 36"
846844
--8<-- "examples/idempotency/src/working_with_validation_payload.py"
847845
```
848846

examples/idempotency/src/working_with_validation_payload.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
from dataclasses import dataclass, field
33
from uuid import uuid4
44

5+
from aws_lambda_powertools import Logger
56
from aws_lambda_powertools.utilities.idempotency import (
67
DynamoDBPersistenceLayer,
78
IdempotencyConfig,
89
idempotent,
910
)
11+
from aws_lambda_powertools.utilities.idempotency.exceptions import IdempotencyValidationError
1012
from aws_lambda_powertools.utilities.typing import LambdaContext
1113

14+
logger = Logger()
15+
1216
table = os.getenv("IDEMPOTENCY_TABLE")
1317
persistence_layer = DynamoDBPersistenceLayer(table_name=table)
1418
config = IdempotencyConfig(
@@ -38,6 +42,12 @@ def lambda_handler(event: dict, context: LambdaContext):
3842
"message": "success",
3943
"statusCode": 200,
4044
}
45+
except IdempotencyValidationError:
46+
logger.exception("Payload tampering detected", payment=payment, failure_type="validation")
47+
return {
48+
"message": "Unable to process payment at this time. Try again later.",
49+
"statusCode": 500,
50+
}
4151
except Exception as exc:
4252
raise PaymentError(f"Error creating payment {str(exc)}")
4353

0 commit comments

Comments
 (0)