List EventBridge Rules that have event bus as a target

Posted: | Updated: | Tags: aws til cloud

The AWS API allows you to list-rules which returns a list of all the rules but does not list targets. The API also provides you with list-targets-by-rule which allows you to list the targets associated with a specific rule. If you want to find all the rules with a specific target, this case an event bus, you can join both of them together.

No idea if this is acceptable practice, or if I’ll ever use this again, but I will unleash this string of commands and pipes to the world.

aws events list-rules --no-paginate | jq '.Rules | .[] | .Name' | tr -d '"' | while read name; do aws events list-targets-by-rule --no-paginate --rule $name | if grep -q ':event-bus'; then echo "$name"; fi; done

This will list all the rules that have an event bus as a target in the same account and Region as well as event buses in a different account or Region. You can modify the grep parameter to find other targets such as replacing ‘:event-bus’ with ‘:sns:’ for SNS topics, for example.


Related ramblings