Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing events in eventBridge that don't match any rule

I am trying to find a way to somehow capture events that do not match a specific rule from an event bus. Below is the event-pattern for a rule that I created:

 {
  "detail": {
      "key1": ["1234"],
      "key2": ["ABC"],
      "key3": ["PHL"]
  }
}

The rule is matched and the target is invoked only if all 3 keys in the pattern are matching.

How do I log or find out the event that was unmatched by this rule and the target wasn't invoked?

Solutions I tried but failed:

  • The dead-letter(DLQ) only captures events that fail due to technical reasons like target resource being down or IAM policy issues.
  • Tried writing the inverse rule using "anything-but" clause but doesn't work if any one key mismatch occurs. Only works if all 3 keys mismatch. (Details here: EventBridge rule "anything-but" pattern)
  • Tried the solution in the below AWS documentation link but I couldn't find the "FailedInvocations" metric anywhere. Also, I'm not sure if that will help with unmatched events: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-troubleshooting.html#eb-create-alarm-broken-event-rules
like image 537
Aniket Kapse Avatar asked Jan 25 '26 13:01

Aniket Kapse


1 Answers

Like what Marcin said ... Its possible to write a Lambda as target with a rule that matches all/most of the events in your EB. The Lambda function will

  1. Loop on ListRules for all events in your custom EB
  2. Foreach rule (not including this new Lambda), do a TestEventPattern
  3. If no matches are found, log to a DLQ

Not a pretty soln I admit ...

See:

https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_ListRules.html https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_TestEventPattern.html

like image 57
Henry Chan Avatar answered Jan 28 '26 11:01

Henry Chan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!