跳至內容

Compare two values in EventBridge rule and only trigger if they're different

0

Hi there!

I'm trying to utilise EventBridge and are creating a rule. I get an event containing an oldState and a newState. If a specific value has changed, I need to trigger the rule.

A good example could be the name of an item:

{
  "detail": {
    "newState": {
      "name": "Potato"
    },
    "oldState": {
      "name": "Potat"
    }
}

I was thinking of using anything-but with the following path:

`$.detail.newState.name"

But that does not seem to work? Any suggestions as to how this should be handled?

E.g.:

{
  "detail": {
    "newState": {
      "name": {
        "anything-but": {
          "prefix": "$.detail.oldState.name"
        }
      }
    },
    "oldState": {
      "name": [{"exists": true}]
    }
  }
}
已提問 4 個月前檢視次數 103 次
1 個回答
0

I believe what you are trying to achieve it's not possible. In EventBridge rules, you cannot directly compare two values within a single event to check if they're different. EventBridge rule patterns are designed for matching specific values, not for performing comparisons between fields.

As a workaround, you can perform the comparison on the producer and add a property to reflect if they are different (something like hasChanged: true, then the rule pattern evaluates this property) or perform the filter on the consumer. The former will avoid unnecesarry executions of the consumer.

AWS
已回答 4 個月前
專家
已審閱 4 個月前
  • Hmm, interesting!

    I'm unable to change the event itself I'm afraid as it is a 3rd party. Moreover, the event contains hundreds of fields that may change - name was just a simple example :)

    It seems so far I'm limited to do an early return in the consumer, but that seems inefficient 🤔

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。