Sub topic 11
Automating alerts with EventBridge
This chapter assumes you can read IAM policy JSON, use the AWS CLI, and have at least one analyzer that produces findings. You should also know how finding status works (active, archived, resolved) from the triage chapter.
Why automate
Checking the Access Analyzer console works for a few findings. It does not scale. A new public bucket policy can sit unnoticed for days. IAM Access Analyzer publishes each finding as an event to Amazon EventBridge, the AWS service that routes events to targets. You write a rule that matches the events you care about and sends them to a target such as an SNS topic, a Lambda function, or an SQS queue.
Access Analyzer sends events to the default event bus in the same account and Region as the analyzer. It sends one when it generates a finding and again when a finding changes, for example when it becomes resolved. Check that your rules and targets are in the Region of the analyzer.
Match findings with an event pattern
An event pattern is a JSON filter. This one matches every Access Analyzer finding:
{
"source": ["aws.access-analyzer"],
"detail-type": ["Access Analyzer Finding"]
}That is too noisy for most teams, because it includes archived and resolved updates. Narrow it by adding fields from the event's detail object. Run a finding through a test rule first, or capture a sample event in a log group, so you can see the exact field names your analyzer type produces. The fields differ between external access and unused access findings.
A narrower pattern for active findings only looks like this:
{
"source": ["aws.access-analyzer"],
"detail-type": ["Access Analyzer Finding"],
"detail": {
"status": ["ACTIVE"]
}
}Create the rule and target
The next commands create a rule, point it at an SNS topic, and set the topic's policy so EventBridge may publish to it. Replace the account ID and Region with your own.
aws sns create-topic --name access-analyzer-alerts
aws events put-rule \
--name access-analyzer-active-findings \
--event-pattern '{"source":["aws.access-analyzer"],"detail-type":["Access Analyzer Finding"],"detail":{"status":["ACTIVE"]}}'
aws events put-targets \
--rule access-analyzer-active-findings \
--targets 'Id=1,Arn=arn:aws:sns:us-east-1:111122223333:access-analyzer-alerts'The topic also needs a resource-based policy that allows the events.amazonaws.com service principal to call sns:Publish. Without it, the rule matches events but delivery fails silently. Check the rule's FailedInvocations CloudWatch metric if no messages arrive.
Choose targets by response
Pick the target that matches how your team responds.
| Goal | Target | Notes |
|---|---|---|
| Tell people | SNS topic | Subscribe email, chat webhooks, or a paging tool |
| Open a ticket | Lambda | Format the event and call your ticketing API |
| Fix automatically | Lambda or Systems Manager Automation | Limit to well-understood cases |
| Keep a record | CloudWatch Logs or S3 | Useful for audits and for testing patterns |
Automatic remediation of unused access deserves caution. Removing a permission that a quarterly job needs causes an outage. Send unused access findings to a human first. Reserve automatic action for clear cases, such as a public bucket policy on a bucket tagged as private.
Combine with archive rules
Archive rules and EventBridge work together. An archive rule marks expected findings as archived when they are created. Use a pattern with "status": ["ACTIVE"] and archived findings no longer page anyone. This keeps alert volume proportional to real risk.
Exercise
Your rule matches Access Analyzer events, but the SNS topic never delivers a message. The rule's FailedInvocations metric is increasing. What is the most likely cause, and where do you fix it?
Show answer
The SNS topic's resource-based policy does not allow the events.amazonaws.com service principal to call sns:Publish. Add a statement to the topic policy that grants that permission, ideally scoped to the rule's ARN with an aws:SourceArn condition.
Exercise
Why should you send unused access findings to a person, not to an automatic remediation function?
Show answer
A permission that looks unused in the tracking period may support infrequent work, such as a quarterly job. Removing it automatically can break that workload, so a person should confirm first.