Sub topic 11
Testing patterns and monitoring rules
This chapter assumes you can write event patterns, create rules, and attach targets with the AWS CLI. It covers how to check a pattern before you rely on it, and how to find out why an event did not arrive.
Test a pattern before you attach it
A rule that never matches fails silently. EventBridge does not report events that matched nothing. Test patterns first with test-event-pattern. It takes a pattern and a sample event, and it prints true or false.
Save the pattern from the earlier chapter as pattern.json. Then save a sample event as sample-event.json. A sample event must be a complete event with its envelope fields. The id, account, time, region, and resources fields are required, even though the pattern does not use them.
{
"id": "1",
"version": "0",
"account": "123456789012",
"time": "2026-11-26T18:00:00Z",
"region": "us-east-1",
"resources": [],
"source": "com.example.orders",
"detail-type": "OrderPlaced",
"detail": {
"orderId": "1001",
"amount": 250,
"status": "new"
}
}aws events test-event-pattern --event-pattern file://pattern.json --event file://sample-event.jsonThe output is { "Result": true } for this event. Change amount to 50 or status to "test" and run it again. You should get false. Test both a matching and a non-matching event every time.
Common reasons a rule does not match
- Wrong value type. A pattern for
"amount": [100]does not match the string"100". Numbers and strings are different. - Detail sent as an object. In
PutEvents,Detailmust be a JSON string. Check the call as well as the pattern. - Field missing in the event. A pattern that names a field requires it to exist, unless you use
exists: false. - Wrong bus. A rule only sees events on its own bus. A rule on the default bus will not match an event sent to
orders-bus. - Case. Matching is case-sensitive.
orderplaceddoes not matchOrderPlaced.
Monitor rules with CloudWatch metrics
EventBridge publishes metrics to CloudWatch in the AWS/Events namespace. They use the dimension RuleName, and also EventBusName for rules on custom buses.
| Metric | What it tells you |
|---|---|
| `TriggeredRules` | The rule matched an event. |
| `Invocations` | EventBridge attempted to invoke the target. |
| `FailedInvocations` | The invocation failed after all retries. |
| `InvocationsFailedToBeSentToDlq` | The event could not be written to the dead-letter queue. |
| `ThrottledRules` | A rule was throttled and delivery was delayed. |
Read the metrics together. If TriggeredRules is zero, the pattern or the bus is the problem. If TriggeredRules rises but Invocations does not, look at the target. If FailedInvocations rises, look at permissions and the target service, and inspect the dead-letter queue.
aws cloudwatch get-metric-statistics \
--namespace AWS/Events \
--metric-name TriggeredRules \
--dimensions Name=RuleName,Value=high-value-orders Name=EventBusName,Value=orders-bus \
--start-time 2026-11-26T17:00:00Z \
--end-time 2026-11-26T19:00:00Z \
--period 300 \
--statistics SumAlarm on failures
Create an alarm on FailedInvocations so failed deliveries are noticed. Set the alarm to treat missing data as not breaching, since a quiet rule publishes no data points.
aws cloudwatch put-metric-alarm \
--alarm-name high-value-orders-failed \
--namespace AWS/Events \
--metric-name FailedInvocations \
--dimensions Name=RuleName,Value=high-value-orders Name=EventBusName,Value=orders-bus \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data notBreachingA debugging workflow
Exercise
A rule on orders-bus shows TriggeredRules of 0 after you publish an event. test-event-pattern returns true for the same event. What should you check next?
Show answer
Check that the event was sent to orders-bus and not the default bus, because a rule only sees events on its own bus. Also check that the PutEvents response had a FailedEntryCount of 0. The pattern is already known to be correct, so the cause is in how the event was published.