Skip to content

Commit 971677f

Browse files
committed
docs(idempotency): cleanup idempotent_decorator section
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent c3404b4 commit 971677f

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

docs/utilities/idempotency.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,25 @@ It will treat the entire event as an idempotency key. That is, the same event wi
163163

164164
### Idempotent_function decorator
165165

166-
Similar to [idempotent decorator](#idempotent-decorator), you can use `idempotent_function` decorator for any synchronous Python function.
166+
For full flexibility, you can use the `idempotent_function` decorator for any synchronous Python function.
167167

168-
When using `idempotent_function`, you must tell us which keyword parameter in your function signature has the data we should use via **`data_keyword_argument`**.
168+
When using this decorator, you **must** call your decorated function using keyword arguments.
169169

170-
!!! tip "We support JSON serializable data, [Python Dataclasses](https://docs.python.org/3.12/library/dataclasses.html){target="_blank" rel="nofollow"}, [Parser/Pydantic Models](parser.md){target="_blank"}, and our [Event Source Data Classes](./data_classes.md){target="_blank"}."
171-
172-
???+ warning "Limitation"
173-
Make sure to call your decorated function using keyword arguments.
170+
You can use `data_keyword_argument` to tell us the argument to extract an idempotency key. We support JSON serializable data, [Dataclasses](https://docs.python.org/3.12/library/dataclasses.html){target="_blank" rel="nofollow"}, Pydantic Models, and [Event Source Data Classes](./data_classes.md){target="_blank"}
174171

175172
=== "Using Dataclasses"
176173

177-
```python hl_lines="3-7 11 26 37"
174+
```python title="working_with_idempotent_function_dataclass.py" hl_lines="3-7 11 26 39"
178175
--8<-- "examples/idempotency/src/working_with_idempotent_function_dataclass.py"
179176
```
180177

178+
1. Notice how **`data_keyword_argument`** matches the name of the parameter.
179+
<br><br> This allows us to extract one or all fields as idempotency key.
180+
2. Different from `idempotent` decorator, we must explicitly register the Lambda context to [protect against timeouts](#lambda-timeouts).
181+
181182
=== "Using Pydantic"
182183

183-
```python hl_lines="1-5 10 23 34"
184+
```python title="working_with_idempotent_function_pydantic.py" hl_lines="1-5 10 23 34"
184185
--8<-- "examples/idempotency/src/working_with_idempotent_function_pydantic.py"
185186
```
186187

examples/idempotency/src/working_with_idempotent_function_dataclass.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ class Order:
2424

2525

2626
@idempotent_function(data_keyword_argument="order", config=config, persistence_store=dynamodb)
27-
def process_order(order: Order):
27+
def process_order(order: Order): # (1)!
2828
return f"processed order {order.order_id}"
2929

3030

3131
def lambda_handler(event: dict, context: LambdaContext):
32-
config.register_lambda_context(context) # see Lambda timeouts section
32+
# see Lambda timeouts section
33+
config.register_lambda_context(context) # (2)!
34+
3335
order_item = OrderItem(sku="fake", description="sample")
3436
order = Order(item=order_item, order_id=1)
3537

0 commit comments

Comments
 (0)