@@ -318,6 +318,34 @@ You can inherit from the `BasePersistenceLayer` class and implement the abstract
318
318
checks inside these methods to ensure the idempotency guarantees remain intact. For example, the `_put_record` method
319
319
needs to raise an exception if a non-expired record already exists in the data store with a matching key.
320
320
321
+ # # Compatibility with other utilities
322
+
323
+ # ## Validation utility
324
+
325
+ The idempotency utility can be used with the `validator` decorator. Ensure that idempotency is the innermost decorator.
326
+
327
+ !!! warning
328
+ If you use an envelope with the validator, the event received by the idempotency utility will be the unwrapped
329
+ event - not the "raw" event Lambda was invoked with. You will need to account for this if you set the
330
+ ` event_key_jmespath` .
331
+
332
+ === "app.py"
333
+ ` ` ` python hl_lines="9 10"
334
+ from aws_lambda_powertools.utilities.validation import validator, envelopes
335
+ from aws_lambda_powertools.utilities.idempotency.idempotency import idempotent
336
+
337
+ persistence_layer = DynamoDBPersistenceLayer(
338
+ event_key_jmespath="[message, username]",
339
+ table_name="IdempotencyTable",
340
+ )
341
+
342
+ @validator(envelope=envelopes.API_GATEWAY_HTTP)
343
+ @idempotent(persistence_store=persistence_layer)
344
+ def lambda_handler(event, context):
345
+ cause_some_side_effects(event['username')
346
+ return {"message": event['message'], "statusCode": 200}
347
+ ` ` `
348
+
321
349
# # Extra resources
322
350
If you're interested in a deep dive on how Amazon uses idempotency when building our APIs, check out
323
351
[this article](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/).
0 commit comments