@@ -75,7 +75,7 @@ storage layer, so you'll need to create a table first.
75
75
76
76
You can quickly start by initializing the ` DynamoDBPersistenceLayer ` class outside the Lambda handler, and using it
77
77
with the ` idempotent ` decorator on your lambda handler. The only required parameter is ` table_name ` , but you likely
78
- want to specify ` event_key_jmespath ` as well .
78
+ want to specify ` event_key_jmespath ` via ` IdempotencyConfig ` .
79
79
80
80
` event_key_jmespath ` : A JMESpath expression which will be used to extract the payload from the event your Lambda handler
81
81
is called with. This payload will be used as the key to decide if future invocations are duplicates. If you don't pass
@@ -100,7 +100,7 @@ this parameter, the entire event will be used as the key.
100
100
payment = create_subscription_payment(
101
101
user=body['user'],
102
102
product=body['product_id']
103
- )
103
+ )
104
104
...
105
105
return {"message": "success", "statusCode": 200, "payment_id": payment.id}
106
106
```
@@ -273,12 +273,42 @@ and we will raise `IdempotencyKeyError` if none was found.
273
273
274
274
=== "app.py"
275
275
276
- ```python hl_lines="4"
277
- IdempotencyConfig(
278
- table_name="IdempotencyTable",
279
- event_key_jmespath="body",
276
+ ```python hl_lines="8"
277
+ from aws_lambda_powertools.utilities.idempotency import (
278
+ IdempotencyConfig, DynamoDBPersistenceLayer, idempotent
279
+ )
280
+
281
+ # Requires "user"."uid" and from the "body" json parsed "order_id" to be present
282
+ config = IdempotencyConfig(
283
+ event_key_jmespath="[user.uid, powertools_json(body).order_id]",
280
284
raise_on_no_idempotency_key=True,
281
285
)
286
+ persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
287
+
288
+ @idempotent(config=config, persistence_store=persistence_layer)
289
+ def handler(event, context):
290
+ pass
291
+ ```
292
+ === "Success Event"
293
+
294
+ ```json
295
+ {
296
+ "user": {
297
+ "uid": "BB0D045C-8878-40C8-889E-38B3CB0A61B1",
298
+ "name": "Foo"
299
+ },
300
+ "body": "{\"order_id\": 10000}"
301
+ }
302
+ ```
303
+ === "Failure Event"
304
+
305
+ ```json
306
+ {
307
+ "user": {
308
+ "name": "Foo"
309
+ },
310
+ "body": "{\"total_amount\": 10000}"
311
+ }
282
312
```
283
313
284
314
### Changing dynamoDB attribute names
0 commit comments