Sub topic 12
Routing findings with EventBridge
This chapter assumes you can read JSON, know what an AWS Region and an IAM role are, and have a GuardDuty detector running. It covers how GuardDuty findings reach Amazon EventBridge, how to write an event pattern that selects the findings you care about, and the errors that most often stop a rule from firing.
How findings reach EventBridge
Amazon EventBridge is a serverless event bus. Services publish events to it, and rules you define match those events and send them to targets such as Lambda, SNS, SQS, or Step Functions.
GuardDuty publishes to the default event bus in the same account and Region as the detector. It sends an event when it creates a finding. It sends another when an existing finding is updated, for example when the same activity recurs. The --finding-publishing-frequency setting you chose when creating the detector controls how often updates are published. New findings are sent within about five minutes.
Security Hub also publishes events to EventBridge. The two sources differ in what they carry, as the table shows.
| Source | `source` value | `detail-type` | Event body |
|---|---|---|---|
| GuardDuty | `aws.guardduty` | `GuardDuty Finding` | GuardDuty's native finding JSON |
| Security Hub | `aws.securityhub` | `Security Hub Findings - Imported` | Findings in the Security Hub format, under `detail.findings` |
Use the GuardDuty source when you want GuardDuty's own fields. Use the Security Hub source when you want one rule for findings from many services.
Writing an event pattern
An event pattern is a JSON document. An event matches when every field in the pattern matches the same field in the event. Values in a list are alternatives, so any one of them can match.
This pattern selects GuardDuty findings with severity 7 or higher:
{
"source": ["aws.guardduty"],
"detail-type": ["GuardDuty Finding"],
"detail": {
"severity": [{ "numeric": [">=", 7] }]
}
}Severity is a number in the event, so you use the numeric operator rather than a string comparison. To narrow the rule to one threat family, add a prefix match on the type:
{
"source": ["aws.guardduty"],
"detail-type": ["GuardDuty Finding"],
"detail": {
"type": [{ "prefix": "UnauthorizedAccess:EC2" }],
"severity": [{ "numeric": [">=", 7] }]
}
}Creating the rule
Save the first pattern as pattern.json, then create the rule and attach a target. This example uses an SNS topic whose ARN you already have.
aws events put-rule \
--name guardduty-high-severity \
--event-pattern file://pattern.json
aws events put-targets \
--rule guardduty-high-severity \
--targets "Id"="notify","Arn"="arn:aws:sns:us-east-1:111122223333:security-alerts"The topic's access policy must allow events.amazonaws.com to publish. A Lambda target needs a resource-based permission that lets EventBridge invoke it. Without either permission the rule matches but delivery fails silently from your point of view.
Common errors
- The rule never fires. Check the Region first. Then check that
sourceanddetail-typematch exactly, including capitalization. - Severity never matches. You probably quoted the number, or used a plain value instead of the
numericoperator. - The rule matches but nothing happens. The target's permissions are missing. Check the target's resource policy and the rule's
FailedInvocationsCloudWatch metric. - Test events do not behave like real ones. Sample findings from
create-sample-findingsdo reach EventBridge. Their type strings carry no special marker, so test rules against sample findings and then confirm against a real one. - Too many notifications. Findings that recur trigger update events. Tighten the pattern, or archive known-benign findings with a suppression rule so they never produce events.
Exercise
A rule in us-east-1 uses source "aws.guardduty" and a severity pattern of [{ "numeric": [">=", 7] }]. GuardDuty is also enabled in eu-west-1, and high-severity findings appear there, but the rule's target never runs for them. Why, and what are two ways to fix it?
Show answer
EventBridge rules are Regional and GuardDuty publishes findings to the default bus in the Region where they occur, so the us-east-1 rule never sees eu-west-1 events. Fix it by creating the same rule and target in eu-west-1, or by adding a rule in eu-west-1 that forwards matching events to a bus in a central Region and attaching the response target there.