Hey all,
On this post there is a solution to have a target rule on a Firehose to add a newline char to every JSON event. However, the solution is for the JS CDK version and doesn't work for the Python version (1.134.0). We tried to find a way to have this solution on Python but seems that the CDK doesn't map all the needed properties from JS to Python.
For now, we have a very ugly workaround that manipulates the JSON template before sending it to CloudFormation.
To create the target firehose we use the code below, where the problem is the RuleTargetInput that have just a few options and doesn't enable a custom InputTransformerProperty.
firehose_target = KinesisFirehoseStream(
stream=self.delivery_stream,
# Python CDK is not allowing Custom CfnRule.InputTransformerProperty
# Makefile will make the workaround
message=RuleTargetInput.from_text(f'{EventField.from_path("$")}'),
)
Piece of the JSON template generated by the CDK:
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"firehose",
"Arn"
]
},
"Id": "Target0",
"InputTransformer": {
"InputPathsMap": {"f1":"$"},
"InputTemplate": "\\"<f1>\\""
},
"RoleArn": {
"Fn::GetAtt": [
"firehoseEventsRole1814C701",
"Arn"
]
}
}
]
To manipulate the InputTransformer, we run the code below before sending it to CloudFormation:
jq -c . cdk.out/robotic-accounting-firehose.template.json \
| sed -e 's/"InputTransformer":{"InputPathsMap":{"f1":"$$"},"InputTemplate":"\\"<f1>\\""}/"InputTransformer":{"InputPathsMap":{},"InputTemplate":"<aws.events.event>\\n"}/g' \
| jq '.' > cdk.out/robotic-accounting-firehose.template.json.tmp
rm cdk.out/robotic-accounting-firehose.template.json
mv cdk.out/robotic-accounting-firehose.template.json.tmp cdk.out/robotic-accounting-firehose.template.json
That gives us the InputTransformer that we need and works:
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"firehose",
"Arn"
]
},
"Id": "Target0",
"InputTransformer": {
"InputPathsMap": {},
"InputTemplate": "<aws.events.event>\n"
},
"RoleArn": {
"Fn::GetAtt": [
"firehoseEventsRole1814C701",
"Arn"
]
}
}
]
We know, it's horrible, but it works.
Does someone else have this problem and a better solution?
Does the CDK v2 solve this?
Tks,
Daniel