@@ -76,6 +76,7 @@ Event Source | Data_class
76
76
[ DynamoDB streams] ( #dynamodb-streams ) | ` DynamoDBStreamEvent ` , ` DynamoDBRecordEventName `
77
77
[ EventBridge] ( #eventbridge ) | ` EventBridgeEvent `
78
78
[ Kafka] ( #kafka ) | ` KafkaEvent `
79
+ [ Kinesis Firehose Delivery Stream] ( #kinesis-firehose-delivery-stream ) | ` KinesisFirehoseEvent `
79
80
[ Kinesis Data Stream] ( #kinesis-streams ) | ` KinesisStreamEvent `
80
81
[ Lambda Function URL] ( #lambda-function-url ) | ` LambdaFunctionUrlEvent `
81
82
[ Rabbit MQ] ( #rabbit-mq ) | ` RabbitMQEvent `
@@ -892,6 +893,45 @@ or plain text, depending on the original payload.
892
893
do_something_with(data)
893
894
```
894
895
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
+
895
935
### Lambda Function URL
896
936
897
937
=== "app.py"
0 commit comments