skip to Main Content

I’ve come across a strange anomoly with Event Bridge.

I have an incoming message to eventbridge. This comes through with some details, namely an array of ‘items’.
In the interest of message brevity and transferring only the data I want to pass on, I’ve setup a rule to transform it down.

The json of the ‘detail’ of the message looks like this:

{"detail" : 
    {"sale" : 
        {"items" : 
            [{
                "product" : "cheese",
                "quantity" : 1
            },
            {
                "product" : "tomato",
                "quantity" : 1
            }]
        }
    }
}

I have tried setting the input transformer to the following but am not getting any success.

$.detail.sale.items
$.detail.sale.items[*]
$.detail.sale.items.*

(the above are either invalid when setting the input transformer, or they simply don’t trigger the rule to send anything on)

However if I use:

$.detail.sale.items[0].quantity

It happily returns the number 1 for me.

It’s almost like EventBridge items with children, you can’t select multiples.
Or items with multiple levels, you need to select the very lowest level to get data the data out.

AWS doco only ever points to examples with lowest level json objects, or singular hard-referenced array items.

Has anyone got this working with child items or arrays?

2

Answers


  1. Chosen as BEST ANSWER

    The correct syntax was:

    $.detail.sale.items
    

    Which works when sending to a lambda function which is my required use case. However I haven’t been able to confirm it working for cloudwatch or sns targets.


  2. I needed something similar once… I needed to create a Rule in an event Bridge and pass an object that contained an array and send it to an SQS target, the payload in the Event Bridge was something like this:
    Event bridge:

    {
       "name": "Diego",
       "document": "9999999",
       "hobbies": ["NETFLIX","FOOTBALL"]
    }
    

    I needed to send only the Name and Hobbies to SQS, so I created my Input Path:

     {
       "orderUuid" : "$.name",
       "hobbies" : "$.hobbies"
     }
    

    And my Input Template:
    The way it worked :

    {
      "name": "<name>",
      "hobbies": <hobbies>
    }
    

    The way I did before and it went wrong:

    {
      "name": "<name>",
      "hobbies": "<hobbies>"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search