Skip to content

Commit 7d4304b

Browse files
author
Michael Brewer
committed
chore(docs): Update the docs
1 parent e2c96eb commit 7d4304b

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

docs/utilities/idempotency.md

+36-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ storage layer, so you'll need to create a table first.
7575

7676
You can quickly start by initializing the `DynamoDBPersistenceLayer` class outside the Lambda handler, and using it
7777
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`.
7979

8080
`event_key_jmespath`: A JMESpath expression which will be used to extract the payload from the event your Lambda handler
8181
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.
100100
payment = create_subscription_payment(
101101
user=body['user'],
102102
product=body['product_id']
103-
)
103+
)
104104
...
105105
return {"message": "success", "statusCode": 200, "payment_id": payment.id}
106106
```
@@ -273,12 +273,42 @@ and we will raise `IdempotencyKeyError` if none was found.
273273

274274
=== "app.py"
275275

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]",
280284
raise_on_no_idempotency_key=True,
281285
)
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+
}
282312
```
283313

284314
### Changing dynamoDB attribute names

0 commit comments

Comments
 (0)