Lesson 1 of 4 Amazon EventBridge and AWS Health

Routing Operational Events with EventBridge Rules

This lesson explains how Amazon EventBridge, a serverless event router and the backbone of most event-driven remediation on AWS, delivers matching events from event buses to targets.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe events and event buses.
  • Write event patterns.
  • Identify common AWS event sources for operations.

Events and event buses

An event is a JSON document with standard top-level fields: source (such as aws.ec2), detail-type (such as EC2 Instance State-change Notification), account, region, time, resources and a service-specific detail object. Every account has a default event bus in each Region that receives events from AWS services. Custom event buses receive events from your applications through PutEvents, and partner event buses receive events from SaaS providers. Buses have resource-based policies that control which accounts may send events to them.

Rules and event patterns

A rule on a bus has either an event pattern or a schedule (schedules on rules are a legacy option; EventBridge Scheduler is preferred). An event pattern matches an event when every field in the pattern matches. Values are arrays of allowed values, and content filters add prefix, suffix, anything-but, numeric ranges, exists and wildcard matching. Matching is exact and case-sensitive, so "state": ["Stopped"] never matches the EC2 value stopped. Each rule can have up to five targets.

{
  "source": ["aws.ec2"],
  "detail-type": ["EC2 Instance State-change Notification"],
  "detail": {
    "state": ["stopped", "terminated"],
    "instance-id": [{"prefix": "i-0"}]
  }
}

The following diagram tests two patterns against the same EC2 event.

How an event pattern matches. Every field in the pattern must match a field in the event, values are arrays of allowed values, and matching is exact and case-sensitive. A pattern with state Stopped never matches the EC2 event, whose value is stopped.
The instance ID is illustrative.
Scenario questions

Does the pattern match?

Exam skills 1.2.2

Decide whether an event pattern matches an event.

Log in to try this activity Interactive activities are free with an account.

Common AWS event sources for operations

Many operational automations start from a handful of AWS event sources. The following table lists the ones that appear most often in exam scenarios.

Sourcedetail-type exampleTypical automation
aws.ec2EC2 Instance State-change NotificationNotify or restart when an instance stops
aws.autoscalingEC2 Instance-launch Lifecycle ActionRun configuration before an instance enters service
aws.cloudwatchCloudWatch Alarm State ChangeStart an Automation runbook from an alarm
aws.healthAWS Health EventNotify about scheduled maintenance or service issues
aws.configConfig Rules Compliance ChangeRemediate non-compliant resources
aws.s3 (EventBridge enabled on bucket)Object CreatedProcess new files
Any service via CloudTrailAWS API Call via CloudTrailReact to a specific API call
aws.trustedadvisorTrusted Advisor Check Item Refresh NotificationRemediate a red check
Match the pairs

Which event source?

Exam skills 1.2.2

Match each operational trigger with the event that EventBridge receives.

Log in to try this activity Interactive activities are free with an account.
Worked example

Restarting stopped production instances

Production instances tagged AlwaysOn=true must be restarted automatically if someone stops them. An EventBridge rule matches EC2 state changes to stopped. Because the event does not contain tags, the target is a Systems Manager Automation runbook that first reads the instance's tags with aws:executeAwsApi, branches with aws:branch if the tag is present, and then calls AWS-StartEC2Instance. An input transformer passes $.detail.instance-id to the runbook's InstanceId parameter, and the rule's IAM role allows ssm:StartAutomationExecution and iam:PassRole for the runbook's assume role.

Check yourself

How many targets can one rule have?

Show answer

Up to five.

Exam Tips

Remember for the exam

  • AWS service events arrive on the default event bus in the Region where they happen.
  • Event patterns are exact and case-sensitive; use content filters for prefixes and ranges.
  • A rule can have up to five targets.
  • Many events lack tags; look them up in the target if the logic depends on tags.