Skip to content

Commit 4855551

Browse files
ryandeivertrubenfonseca
authored andcommitted
update docs for KinesisFirehoseEvent
1 parent ab36af5 commit 4855551

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/utilities/data_classes.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Event Source | Data_class
7676
[DynamoDB streams](#dynamodb-streams) | `DynamoDBStreamEvent`, `DynamoDBRecordEventName`
7777
[EventBridge](#eventbridge) | `EventBridgeEvent`
7878
[Kafka](#kafka) | `KafkaEvent`
79+
[Kinesis Firehose Delivery Stream](#kinesis-firehose-delivery-stream) | `KinesisFirehoseEvent`
7980
[Kinesis Data Stream](#kinesis-streams) | `KinesisStreamEvent`
8081
[Lambda Function URL](#lambda-function-url) | `LambdaFunctionUrlEvent`
8182
[Rabbit MQ](#rabbit-mq) | `RabbitMQEvent`
@@ -892,6 +893,45 @@ or plain text, depending on the original payload.
892893
do_something_with(data)
893894
```
894895

896+
### Kinesis Firehose Delivery Stream
897+
898+
Kinesis Firehose Data Transformation can use a Lambda Function to modify the records
899+
inline, and re-emit them back to the Delivery Stream.
900+
901+
Similar to Kinesis Data Streams, the events contain base64 encoded data. You can use the helper
902+
function to access the data either as json or plain text, depending on the original payload.
903+
904+
=== "app.py"
905+
906+
```python
907+
import base64
908+
import json
909+
from aws_lambda_powertools.utilities.data_classes import event_source, KinesisFirehoseEvent
910+
911+
@event_source(data_class=KinesisFirehoseEvent)
912+
def lambda_handler(event: KinesisFirehoseEvent, context):
913+
result = []
914+
for rec in event.records:
915+
# if data was delivered as json; caches loaded value
916+
data = kinesis_firehose_record.data_as_json
917+
918+
# or swap for below if data was delivered as text
919+
# data = kinesis_firehose_record.data_as_text
920+
921+
modified_record = do_sometime(data)
922+
923+
firehose_record_output = {
924+
"recordId": rec.record_id,
925+
"data": base64.b64encode(json.dump(modified_record).encode('utf-8')),
926+
"result": "Ok"
927+
}
928+
929+
result.append(firehose_record_output)
930+
931+
# return transformed records
932+
return = {'records': result}
933+
```
934+
895935
### Lambda Function URL
896936

897937
=== "app.py"

0 commit comments

Comments
 (0)