Skip to content

Commit 4d10ff8

Browse files
Addressing Andrea's feedback
1 parent 9244833 commit 4d10ff8

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

docs/utilities/parser.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The Parser utility simplifies data parsing and validation using [Pydantic](https
1313
- Parse and validate Lambda event payloads
1414
- Built-in support for common AWS event sources
1515
- Runtime type checking with user-friendly error messages
16-
- Compatible with Pydantic v2
16+
- Compatible with Pydantic v2.x
1717

1818
## Getting started
1919

@@ -22,14 +22,14 @@ The Parser utility simplifies data parsing and validation using [Pydantic](https
2222
Powertools only supports Pydantic v2, so make sure to install the required dependencies for Pydantic v2 before using the Parser.
2323

2424
```python
25-
pip install aws-lambda-powertools[tracer]
25+
pip install aws-lambda-powertools[parser]
2626
```
2727

2828
!!! info "This is not necessary if you're installing Powertools for AWS Lambda (Python) via [Lambda Layer/SAR](../index.md#lambda-layer){target="_blank"}"
2929

30-
You can also add as a dependency in your preferred tool: `e.g., requirements.txt, pyproject.toml`.
30+
You can also add as a dependency in your preferred tool: `e.g., requirements.txt, pyproject.toml`, etc.
3131

32-
### Data Model with Parse
32+
### Data Model with Parser
3333

3434
You can define models by inheriting from `BaseModel` or any other supported type through `TypeAdapter` to parse incoming events. Pydantic then validates the data, ensuring that all fields conform to the specified types and maintaining data integrity.
3535

@@ -38,7 +38,7 @@ You can define models by inheriting from `BaseModel` or any other supported type
3838

3939
#### Event parser
4040

41-
The `@event_parser` decorator automatically parses the incoming event into the specified Pydantic model `MyEvent`. If the input doesn't match the model's structure or type requirements, we raises a `ValidationError` directly from Pydantic.
41+
The `@event_parser` decorator automatically parses the incoming event into the specified Pydantic model `MyEvent`. If the input doesn't match the model's structure or type requirements, it raises a `ValidationError` directly from Pydantic.
4242

4343
=== "getting_started_with_parser.py"
4444

@@ -68,7 +68,7 @@ You can use the `parse()` function when you need to have flexibility with differ
6868
--8<-- "examples/parser/src/example_event_parser.json"
6969
```
7070

71-
#### Keys difference between parse and event_parser
71+
#### Keys differences between parse and event_parser
7272

7373
The `parse()` function offers more flexibility and control:
7474

@@ -84,7 +84,7 @@ The `@event_parser` decorator is ideal for:
8484

8585
### Built-in models
8686

87-
You can use pre-built models provided by the Parser for parsing events from AWS services, so you don’t need to create these models yourself, we’ve already done that for you.
87+
You can use pre-built models to work events from AWS services, so you don’t need to create them yourself. We’ve already done that for you!
8888

8989
=== "sqs_model_event.py"
9090

@@ -158,7 +158,7 @@ Use the model to validate and extract relevant information from the incoming eve
158158

159159
### Envelopes
160160

161-
You can use **Envelopes**, which are **JMESPath expressions**, to extract specific portions of complex, nested JSON structures. This is useful when your actual payload is wrapped around a known structure, for example Lambda Event Sources like **EventBridge**.
161+
You can use **Envelopes** to extract specific portions of complex, nested JSON structures. This is useful when your actual payload is wrapped around a known structure, for example Lambda Event Sources like **EventBridge**.
162162

163163
Envelopes can be used via `envelope` parameter available in both `parse` function and `event_parser` decorator.
164164

@@ -181,23 +181,23 @@ You can use pre-built envelopes provided by the Parser to extract and parse spec
181181
| Envelope name | Behaviour | Return |
182182
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
183183
| **DynamoDBStreamEnvelope** | 1. Parses data using `DynamoDBStreamModel`. `` 2. Parses records in `NewImage` and `OldImage` keys using your model. `` 3. Returns a list with a dictionary containing `NewImage` and `OldImage` keys | `List[Dict[str, Optional[Model]]]` |
184-
| **EventBridgeEnvelope** | 1. Parses data using `EventBridgeModel`. ``2. Parses`detail` key using your model and returns it. | `Model` |
185-
| **SqsEnvelope** | 1. Parses data using `SqsModel`. ``2. Parses records in`body` key using your model and return them in a list. | `List[Model]` |
186-
| **CloudWatchLogsEnvelope** | 1. Parses data using `CloudwatchLogsModel` which will base64 decode and decompress it. ``2. Parses records in`message` key using your model and return them in a list. | `List[Model]` |
187-
| **KinesisDataStreamEnvelope** | 1. Parses data using `KinesisDataStreamModel` which will base64 decode it. ``2. Parses records in in`Records` key using your model and returns them in a list. | `List[Model]` |
188-
| **KinesisFirehoseEnvelope** | 1. Parses data using `KinesisFirehoseModel` which will base64 decode it. ``2. Parses records in in`Records` key using your model and returns them in a list. | `List[Model]` |
189-
| **SnsEnvelope** | 1. Parses data using `SnsModel`. ``2. Parses records in`body` key using your model and return them in a list. | `List[Model]` |
184+
| **EventBridgeEnvelope** | 1. Parses data using `EventBridgeModel`. ``2. Parses `detail` key using your model`` and returns it. | `Model` |
185+
| **SqsEnvelope** | 1. Parses data using `SqsModel`. ``2. Parses records in `body` key using your model`` and return them in a list. | `List[Model]` |
186+
| **CloudWatchLogsEnvelope** | 1. Parses data using `CloudwatchLogsModel` which will base64 decode and decompress it. ``2. Parses records in `message` key using your model`` and return them in a list. | `List[Model]` |
187+
| **KinesisDataStreamEnvelope** | 1. Parses data using `KinesisDataStreamModel` which will base64 decode it. ``2. Parses records in in `Records` key using your model`` and returns them in a list. | `List[Model]` |
188+
| **KinesisFirehoseEnvelope** | 1. Parses data using `KinesisFirehoseModel` which will base64 decode it. ``2. Parses records in in` Records` key using your model`` and returns them in a list. | `List[Model]` |
189+
| **SnsEnvelope** | 1. Parses data using `SnsModel`. ``2. Parses records in `body` key using your model`` and return them in a list. | `List[Model]` |
190190
| **SnsSqsEnvelope** | 1. Parses data using `SqsModel`. `` 2. Parses SNS records in `body` key using `SnsNotificationModel`. `` 3. Parses data in `Message` key using your model and return them in a list. | `List[Model]` |
191-
| **ApiGatewayEnvelope** | 1. Parses data using `APIGatewayProxyEventModel`. ``2. Parses`body` key using your model and returns it. | `Model` |
192-
| **ApiGatewayV2Envelope** | 1. Parses data using `APIGatewayProxyEventV2Model`. ``2. Parses`body` key using your model and returns it. | `Model` |
193-
| **LambdaFunctionUrlEnvelope** | 1. Parses data using `LambdaFunctionUrlModel`. ``2. Parses`body` key using your model and returns it. | `Model` |
194-
| **KafkaEnvelope** | 1. Parses data using `KafkaRecordModel`. ``2. Parses`value` key using your model and returns it. | `Model` |
195-
| **VpcLatticeEnvelope** | 1. Parses data using `VpcLatticeModel`. ``2. Parses`value` key using your model and returns it. | `Model` |
196-
| **BedrockAgentEnvelope** | 1. Parses data using `BedrockAgentEventModel`. ``2. Parses`inputText` key using your model and returns it. | `Model` |
191+
| **ApiGatewayEnvelope** | 1. Parses data using `APIGatewayProxyEventModel`. ``2. Parses `body` key using your model`` and returns it. | `Model` |
192+
| **ApiGatewayV2Envelope** | 1. Parses data using `APIGatewayProxyEventV2Model`. ``2. Parses `body` key using your model`` and returns it. | `Model` |
193+
| **LambdaFunctionUrlEnvelope** | 1. Parses data using `LambdaFunctionUrlModel`. ``2. Parses `body` key using your model`` and returns it. | `Model` |
194+
| **KafkaEnvelope** | 1. Parses data using `KafkaRecordModel`. ``2. Parses `value` key using your model`` and returns it. | `Model` |
195+
| **VpcLatticeEnvelope** | 1. Parses data using `VpcLatticeModel`. ``2. Parses `value` key using your model`` and returns it. | `Model` |
196+
| **BedrockAgentEnvelope** | 1. Parses data using `BedrockAgentEventModel`. ``2. Parses `inputText` key using your model`` and returns it. | `Model` |
197197

198198
#### Bringing your own envelope
199199

200-
You can create your own Envelope model and logic by inheriting from `BaseEnvelope`, and implementing the `parse` method or `@event_parser` decorator.
200+
You can create your own Envelope model and logic by inheriting from `BaseEnvelope`, and implementing the `parse` method.
201201

202202
Here's a snippet of how the EventBridge envelope we demonstrated previously is implemented.
203203

0 commit comments

Comments
 (0)