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
Copy file name to clipboardExpand all lines: docs/content/utilities/parser.mdx
+118-4Lines changed: 118 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,10 @@ These are simply Python classes that inherit from BaseModel. **Parser** enforces
57
57
Use Koudai Aono's <ahref="https://github.com/koxudaxi/datamodel-code-generator">data model code generation tool for Pydantic</a>
58
58
</Note><br/>
59
59
60
+
### Extending built-in models
61
+
62
+
**TBW**
63
+
60
64
## Parsing events
61
65
62
66
You can parse inbound events using **event_parser** decorator, or the standalone `parse` function. Both are also able to parse either dictionary or JSON string as an input.
**DynamoDBStreamEnvelope** | 1. Parses data using `DynamoDBStreamModel`. <br/> 2. Parses records in `NewImage` and `OldImage` keys using your model. <br/> 3. Returns a list with a dictionary containing `NewImage` and `OldImage` keys | `List[Dict[Literal["NewImage", "OldImage"], BaseModel]]`
285
+
**EventBridgeEnvelope** | 1. Parses data using `EventBridgeModel`. <br/> 2. Parses `detail` key using your model and returns it. | `BaseModel`
286
+
**SqsEnvelope** | 1. Parses data using `SqsModel`. <br/> 2. Parses records in `body` key using your model and return them in a list. | `List[BaseModel]`
287
+
288
+
### Bringing your own envelope model
289
+
290
+
You can create your own Envelope model and logic by inheriting from `BaseEnvelope`, and implementing the `parse` method.
291
+
292
+
Here's an snippet of how the EventBridge Envelope we demonstrated previously is implemented.
293
+
294
+
**EventBridge Model**
295
+
296
+
```python:title=eventbridge_model.py
297
+
from datetime import datetime
298
+
from typing import Any, Dict, List
299
+
300
+
from aws_lambda_powertools.utilities.parser import BaseModel, Field
0 commit comments