1

I have an EventBridge event in a pattern similar to below.

{
  "version": "0",
  "id": "816c9de5-517b-a18a-1190-e3e3c2f51f92",
  "detail-type": "ProductTableEvent",
  "source": "pi-data",
  "account": "751354400372",
  "time": "2022-07-07T05:58:26Z",
  "region": "eu-west-1",
  "resources": [],
  "detail": {
    "data": {
      "new": {
        "Gtin": "01234567",
        "NoIngredientsNeeded": 1,
        "DeliveryCostIncluded": 0,
        "MaximumOrder": 0,
        "ProductSegment": "Vardag",
        "StoreProducts": [],
      }
    }
  }
}

And I want to write an event pattern that get triggers when the storeProducts List is not empty.

As not empty is not same as checking for null, I cant use anything-but rule that checks for null. So none of the below rules works here.

  InsertProductRule:
    Type: 'AWS::Events::Rule'
    Properties:
      EventBusName: commerce
      EventPattern:
        source:
          - "my-source"
        detail
          data: 
            new:  
              StoreProducts:
                - exists: true
                - anything-but: []

Any idea how to do it?

Thank you very much!

0

1 Answer 1

4

You can use the following pattern:

{
  "source": ["pi-data"],
  "detail": {
    "data": {
      "new": {
        "StoreProducts": [{ "exists": true }]
      }
    }
  }
}

this will be triggered when StoreProducts is not an empty list.


When StoreProducts is an empty list:

enter image description here

When StoreProducts is not an empty list:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

No. exists true only check whether StoreProducts property exists. In my case it exists. It is just an empty list.
@ChathuriGunawardhana you are mistaken. Test the pattern I gave you in the EventBridge pattern editor
yes you are right. Trigger skips the empty list with exists filter. I was so caught on phrase "Exists matching works on the presence or absence of a field in the JSON of the event" and was trying to get it work with both exists and anything-but but never tried just with exists. Thank you very much!
I tried this rule for an array of objects and it doesn't work. Is there a different patter for array of primitives or objects?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.