I have EventBus, which has a rule with certain target. There is an InputTransformer inside the target with the InputPath and InputTemplate. I want the transformation to the Array as a result.
I send custom event to EventBus with the detail field, in which I have desired JSON
{
"version": "0",
"id": "9fd93571-3201-4e0d-6cf0-328ff344c9e3",
"detail-type": "test",
"source": "foobar",
"account": "192675374686",
"time": "2023-10-10T11:22:01Z",
"region": "us-east-1",
"resources": [],
"detail": {
"address": {
"field": "888",
"innerField": {
"someInnerField": "999"
}
}
}
}
My expected output is the Array, when I try this InputPath and InputTemplate adding the square brackets, it sends it without double quotes, but it does some transformation.
InputPath
{
"detail": "$.detail"
}
InputTemplate
[{
"customField": <detail>
}]
Actual Output (Message taken from dead-letter queue which configured with target, it was send there, because of invalid json, which is true)
[{
"customField": {address:{field:888,innerField:{someInnerField:999}}}
}]
Expected Output
[{
"customField": {
"address": {
"field": "888",
"innerField": {
"someInnerField": "999"
}
}
}
}]
I don't want to do any mapping, just want to put the whole JSON of the **detail **field into an array with one object with property "customField": and JSON string as a value.
[{ "customField": <here json string from detail> }]
It works as expected with a simple template without square brackets, but I need an array:
{
"customField": <detail>
}
Output
{
"customField": {
"address": {
"field": "888",
"innerField": {
"someInnerField": "999"
}
}
}
}
What will totally work, but it doesn't work for JSON with a lot of fields
Sure, we can map every field inside InputPath and then put it inside template via variables. Already checked it, works.
Path
{
"field": "$.detail.address.field",
"someInnerField": "$.detail.address.innerField.someInnerField"
}
Template
[{
"customField": {
"address": {
"field": "<field>"
"innerField": {
"someInnerField": "<someInnerField>"
}
}
}
}]
We have a similar InputTransformer with EventBridge pipes and seems it should work as I want (See output), but in the end, it doesn't, I receive string without double quotes
Unfortunately there is no way to achieve what you're asking. The EventBridge InputTransformers try to be slightly clever to give you help and make sure you have a valid output, but in this case it harms not helps.
The logic is essentially: "Are you trying to create a JSON output? If so, try to create valid JSON. If NOT, try to create a valid string. And that means removing quotes so that you don't have to escape them."
Unfortunately, the decision is today based solely on whether the Input transformer starts with a {
. A transformer that starts with [
, is treated as a string not JSON.
This is how the service worked since the feature launch in 2016, so unfortunately we cannot change the default behaviour without breaking existing customers.
However, the EventBridge team is evaluating options of how to allow the behaviour you desire to be opted-in.