You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(idempotency): use tab navigation, improves custom serializer example, and additional explanations (aws-powertools#3067)
* fix(parameters): make cache aware of single vs multiple calls
Signed-off-by: heitorlessa <[email protected]>
* chore: cleanup, add test for single and nested
Signed-off-by: heitorlessa <[email protected]>
* docs: improves navigation, custom example, explanations
Signed-off-by: heitorlessa <[email protected]>
---------
Signed-off-by: heitorlessa <[email protected]>
Co-authored-by: Simon Thulbourn <[email protected]>
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+45-21
Original file line number
Diff line number
Diff line change
@@ -154,43 +154,67 @@ When using `idempotent_function`, you must tell us which keyword parameter in yo
154
154
155
155
#### Output serialization
156
156
157
-
The default return of the `idempotent_function` decorator is a JSON object, but you can customize the function's return type by utilizing the `output_serializer` parameter. The output serializer supports any JSON serializable data, **Python Dataclasses** and **Pydantic Models**.
157
+
By default, `idempotent_function` serializes, stores, and returns your annotated function's result as a JSON object. You can change this behavior using `output_serializer` parameter.
158
+
159
+
The output serializer supports any JSON serializable data, **Python Dataclasses** and **Pydantic Models**.
158
160
159
161
!!! info "When using the `output_serializer` parameter, the data will continue to be stored in DynamoDB as a JSON object."
160
162
161
-
Working with Pydantic Models:
163
+
=== "Pydantic"
162
164
163
-
=== "Explicitly passing the Pydantic model type"
165
+
You can use `PydanticSerializer` to automatically serialize what's retrieved from the persistent storage based on the return type annotated.
1. We'll use `OrderOutput` to instantiate a new object using the data retrieved from persistent storage as input. <br><br> This ensures the return of the function is not impacted when `@idempotent_function` is used.
1. We'll use `OrderOutput` to instantiate a new object using the data retrieved from persistent storage as input. <br><br> This ensures the return of the function is not impacted when `@idempotent_function` is used.
189
194
190
-
```python hl_lines="9 33 37 41-44 51 54"
195
+
=== "Explicit model type"
196
+
197
+
Alternatively, you can provide an explicit model as an input to `DataclassSerializer`.
1. This function does the following <br><br>**1**. Receives the return from `process_order`<br> **2**. Converts to dictionary before it can be saved into the persistent storage.
215
+
2. This function does the following <br><br>**1**. Receives the dictionary saved into the persistent storage <br>**1** Serializes to `OrderOutput` before `@idempotent` returns back to the caller.
216
+
3. This serializer receives both functions so it knows who to call when to serialize to and from dictionary.
217
+
194
218
#### Batch integration
195
219
196
220
You can can easily integrate with [Batch utility](batch.md){target="_blank"} via context manager. This ensures that you process each record in an idempotent manner, and guard against a [Lambda timeout](#lambda-timeouts) idempotent situation.
0 commit comments