SkillSprout
Chapter 1 · Lesson 3
Intermediate
6 min read

EventBridge and Operational Automation

Overview

Amazon EventBridge is a serverless event bus. AWS services emit events when something changes – an EC2 instance stops, a GuardDuty finding appears, a backup job fails – and rules match those events and route them to targets such as Lambda, SNS, SQS or Systems Manager Automation.

It works like a mail-sorting room: every envelope (event) arrives at the same bus, and your rules say "if the envelope looks like this, deliver it to that department". For operations, that means you can react automatically instead of watching consoles.

On SOA-C03, EventBridge is the glue for auto-remediation, scheduled jobs and AWS Health notifications.

Key Concepts

  • Event buses: the default bus receives AWS service events; custom and partner buses receive your own and SaaS events.
  • A rule has an event pattern (JSON match) or a schedule (cron/rate) and up to 5 targets.
  • Targets include Lambda, SNS, SQS, Step Functions, SSM Run Command/Automation, ECS tasks, Kinesis, API destinations and other buses.
  • EventBridge Scheduler is a separate, scalable scheduler for one-off and recurring tasks with time zones.
  • AWS Health events (e.g. scheduled EC2 retirement) can notify and trigger remediation.
  • Use input transformers to reshape events before delivery.
  • Failed deliveries can be retried and sent to an SQS dead-letter queue.
  • Archive and replay events for debugging; cross-account delivery via bus resource policies.

Detailed Notes

Event pattern example

Alert when any instance in production enters the stopped state:

json
{
  "source": ["aws.ec2"],
  "detail-type": ["EC2 Instance State-change Notification"],
  "detail": { "state": ["stopped", "terminated"] }
}
bash
aws events put-rule --name ec2-stopped --event-pattern file://pattern.json
aws events put-targets --rule ec2-stopped \
  --targets "Id"="1","Arn"="arn:aws:sns:us-east-1:111122223333:ops-alerts"

Scheduled rules vs Scheduler

FeatureScheduled ruleEventBridge Scheduler
Expressionscron, ratecron, rate, one-time (at)
Time zoneUTC onlyTime-zone aware
ScaleLimited rules per busMillions of schedules
TargetsRule targets270+ API actions directly

Auto-remediation patterns

Trigger eventRemediation target
Config rule NON_COMPLIANT (e.g. open SSH)SSM Automation AWS-DisablePublicAccessForSecurityGroup
EC2 stopped unexpectedlyLambda to start instance and tag
GuardDuty finding high severityLambda to isolate instance (swap SG) + SNS
Backup job FAILEDSNS + OpsItem
AWS Health scheduled retirementAutomation to stop/start instance

Rule with an SSM Automation target (CloudFormation)

yaml
Resources:
  StopRule:
    Type: AWS::Events::Rule
    Properties:
      EventPattern:
        source: [aws.ec2]
        detail-type: [EC2 Instance State-change Notification]
        detail: { state: [stopped] }
      Targets:
        - Id: restart
          Arn: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/AWS-RestartEC2Instance:$DEFAULT
          RoleArn: !GetAtt EventsRole.Arn
          InputTransformer:
            InputPathsMap: { id: $.detail.instance-id }
            InputTemplate: '{"InstanceId":[<id>]}'

The RoleArn is required for targets such as Automation, Run Command and Step Functions; Lambda and SNS use resource-based policies instead.

Delivery guarantees and troubleshooting

  • Delivery is at-least-once; make targets idempotent.
  • Metrics Invocations, FailedInvocations and TriggeredRules show whether rules fire.
  • A rule that never triggers is usually a pattern mismatch (wrong detail-type or case) or created in the wrong Region.
  • Events from S3 object-level activity require EventBridge notifications enabled on the bucket; API-call events require CloudTrail management events.

Event sources worth knowing

AWS Config compliance changes, Health, Backup, CodePipeline, Auto Scaling lifecycle, Trusted Advisor check changes, Security Hub findings, and API calls recorded by CloudTrail (detail-type AWS API Call via CloudTrail).### Troubleshooting event bus rules

When a rule "does nothing", walk the pipeline: event arrives on the bus, a rule pattern matches, the target is invoked, the target succeeds.

bash
aws events test-event-pattern --event-pattern file://pattern.json --event file://sample-event.json
aws events list-targets-by-rule --rule ec2-state-change
aws cloudwatch get-metric-statistics --namespace AWS/Events --metric-name FailedInvocations \
  --dimensions Name=RuleName,Value=ec2-state-change --start-time 2025-01-01T00:00:00Z --end-time 2025-01-01T06:00:00Z \
  --period 300 --statistics Sum
aws events put-targets --rule ec2-state-change --targets 'Id=1,Arn=arn:aws:lambda:us-east-1:111122223333:function:remediate,DeadLetterConfig={Arn=arn:aws:sqs:us-east-1:111122223333:eb-dlq},RetryPolicy={MaximumRetryAttempts=5,MaximumEventAgeInSeconds=3600}'
SymptomLikely causeFix
Rule never firesPattern mismatch (case-sensitive, wrong detail-type), rule on the wrong bus or Regiontest-event-pattern; check the event JSON in CloudTrail
MatchedEvents > 0 but target does nothingMissing target permission (Lambda resource policy, SNS/SQS policy, IAM role for the target)Add events.amazonaws.com invoke permission
FailedInvocations risingTarget throttled, deleted or unreachableConfigure DLQ and retry policy, fix target
Cross-account events not receivedMissing bus resource policy or rule in the sender accountAllow events:PutEvents from the sender; add a rule forwarding to the other bus
Scheduled rule off by hoursCron in UTCUse EventBridge Scheduler with a time zone
Event content unusableTarget expects a different shapeInput transformer or EventBridge Pipes for filtering and enrichment

Route, enrich and deliver: rules route by pattern; input transformers reshape payloads; EventBridge Pipes connect a source (SQS, DynamoDB stream, Kinesis) to a target with optional filtering and an enrichment step (Lambda, API destination); archives and replay let you re-send past events after fixing a consumer. Default AWS-service events go to the default bus only; custom applications use custom buses.

Real World Example

Scenario – closing risky security groups automatically. The security team requires that no security group exposes SSH to 0.0.0.0/0. An AWS Config managed rule flags violating groups. A Config compliance-change event matches an EventBridge rule, which starts the SSM Automation runbook that removes the offending rule and posts to Slack through SNS and Lambda.

Violations are corrected in under a minute without a human, and the Config timeline plus CloudTrail provide evidence for auditors.

Architecture Diagram

Event-driven remediation
Architecture
AWS Cloud
Config ruleNON_COMPLIANT
EventBridge rule
SSM Automationfix resource
SNSnotify team
  1. 1A resource changes and AWS Config evaluates it as non-compliant.
  2. 2Config emits a compliance change event onto the default event bus.
  3. 3An EventBridge rule matches the pattern and invokes its targets.
  4. 4Automation fixes the resource while SNS notifies the team.

Best Practices

  • ✓Prefer EventBridge rules to polling scripts for reacting to state changes.
  • ✓Give every target a DLQ and alarm on FailedInvocations.
  • ✓Make remediation idempotent and scoped with tags to avoid touching the wrong resources.
  • ✓Use Scheduler for time-zone-aware or one-off jobs; keep rules for event matching.
  • ✓Enable archive and replay on critical buses to test rule changes.

Common Interview Questions

Exam Tips

SOA-C03 focus

  • React to AWS service state changes -> EventBridge rule; scheduled work -> Scheduler or schedule rule.
  • Remediating non-compliant resources automatically -> Config + EventBridge + SSM Automation (or Config remediation actions).
  • Scheduled EC2 retirement notices -> AWS Health events through EventBridge.
  • API-call-based events require CloudTrail to be enabled.

Finished this lesson?

0 of 46 lessons done · 0% of the course