Skip to content

Commit e11c718

Browse files
committed
docs: improve transforming records example
1 parent c039480 commit e11c718

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/utilities/data_classes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,13 @@ To do that, you can use `KinesisFirehoseDataTransformationResponse` class along
985985

986986
=== "Transforming streaming records"
987987

988-
```python
988+
```python hl_lines="2-3 12 28"
989989
--8<-- "examples/event_sources/src/kinesis_firehose_delivery_stream.py"
990990
```
991991

992+
1. **Ingesting JSON payloads?** <br><br> Use `record.data_as_json` to easily deserialize them.
993+
2. For your convenience, `base64_from_json` serializes a dict to JSON, then encode as base64 data.
994+
992995
=== "Dropping invalid records"
993996

994997
```python

examples/event_sources/src/kinesis_firehose_delivery_stream.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ def lambda_handler(event: KinesisFirehoseEvent, context: LambdaContext):
1313

1414
for record in event.records:
1515
# get original data using data_as_text property
16-
data = record.data_as_text
16+
data = record.data_as_text # (1)!
1717

18-
## do all kind of stuff with data
1918
## generate data to return
2019
transformed_data = {"new_data": "transformed data using Powertools", "original_payload": data}
2120

2221
processed_record = record.build_data_transformation_response(
23-
data=base64_from_json(transformed_data),
22+
data=base64_from_json(transformed_data), # (2)!
2423
)
2524

2625
result.add_record(processed_record)

0 commit comments

Comments
 (0)