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/utilities/batch.md
+141Lines changed: 141 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -707,6 +707,147 @@ You need to create a function to handle each record from the batch - We call it
707
707
708
708
## Advanced
709
709
710
+
### Pydantic integration
711
+
712
+
You can bring your own Pydantic models via **`model`** parameter when inheriting from **`SqsRecordModel`**, **`KinesisDataStreamRecord`**, or **`DynamoDBStreamRecordModel`**
713
+
714
+
Inheritance is importance because we need to access message IDs and sequence numbers from these records in the event of failure. Mypy is fully integrated with this utility, so it should identify whether you're passing the incorrect Model.
715
+
716
+
717
+
=== "SQS"
718
+
719
+
```python hl_lines="5 9-10 12-19 21 27"
720
+
import json
721
+
722
+
from aws_lambda_powertools import Logger, Tracer
723
+
from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor
724
+
from aws_lambda_powertools.utilities.parser.models import SqsRecordModel
725
+
from aws_lambda_powertools.utilities.typing import LambdaContext
726
+
727
+
728
+
class Order(BaseModel):
729
+
item: dict
730
+
731
+
class OrderSqsRecord(SqsRecordModel):
732
+
body: Order
733
+
734
+
# auto transform json string
735
+
# so Pydantic can auto-initialize nested Order model
0 commit comments