내용으로 건너뛰기

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 🤔

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠