Passer au contenu

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}]
    }
  }
}
demandé il y a 4 mois101 vues
1 réponse
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
répondu il y a 4 mois
EXPERT
vérifié il y a 4 mois
  • 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 🤔

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.