โšก Onwuachi Control Plane

EventBridge: Event-Driven Automation

Overview

EventBridge is AWS’s event bus โ€” it routes events from AWS services, custom applications, and SaaS partners to targets like Lambda, SNS, SSM, and Step Functions. It replaces polling and cron jobs with event-driven automation: when X happens, do Y automatically.

Why It Matters

Without EventBridge, reacting to AWS infrastructure events requires polling APIs on a schedule, missing events between polls, or building custom webhook infrastructure. EventBridge makes every AWS service emit events that can trigger immediate automated responses โ€” no polling, no missed events, no custom infrastructure.

Where It Fits

DOP-C02 Domain 4 โ€” Monitoring and Logging

AWS Service emits event (ASG launch, CodePipeline state change, Config violation) | v EventBridge default event bus | v Rule evaluation (pattern match or schedule) | v Target (Lambda / SNS / SSM Automation / Step Functions / SQS)


The Big Picture

Your platform today AWS Equivalent

Cron job (polling) โ†’ EventBridge Scheduled Rule “if X happens, run Y” โ†’ EventBridge Pattern Rule โ†’ Target Manual runbook trigger โ†’ EventBridge โ†’ SSM Automation


Core Concepts

Two rule types:

Scheduled rules โ€” replace cron jobs:

rate(5 minutes) โ€” every 5 minutes rate(1 hour) โ€” every hour cron(0 2 * * ? *) โ€” every day at 2am UTC cron(0 8 ? * MON-FRI *) โ€” weekdays at 8am UTC

Event pattern rules โ€” react to AWS service events:

{
  "source": ["aws.autoscaling"],
  "detail-type": ["EC2 Instance Launch Successful"],
  "detail": {
    "AutoScalingGroupName": ["dop-lab-asg"]
  }
}

Filter on any field in the event detail โ€” specific ASG, region, instance type, status.

Common targets:

Lambda โ€” run custom code SNS โ€” notify humans or other systems SSM Automation โ€” run a runbook (remediation) Step Functions โ€” start a workflow SQS โ€” queue for async processing EC2 / ECS โ€” start/stop instances or tasks

SNS topic resource policy requirement: EventBridge must be explicitly allowed to publish to SNS:

{
  "Effect": "Allow",
  "Principal": {"Service": "events.amazonaws.com"},
  "Action": "sns:Publish",
  "Resource": "<topic-arn>"
}

Without this policy, EventBridge silently fails to deliver โ€” no error surfaced in the rule itself.

Custom events โ€” source namespace restriction: put-events cannot use aws.* as source โ€” that namespace is reserved for AWS services. Custom events must use your own source name: custom.myapp, platform.ops, etc.


Real-World Example

Live lab in devopslab, account 046685909731:

  1. Created rule dop-lab-asg-launch-notify โ€” pattern matching EC2 Instance Launch Successful for dop-lab-asg
  2. Wired SNS topic dop-lab-alerts as target
  3. First attempt: no email โ€” SNS topic missing EventBridge resource policy
  4. Added resource policy allowing events.amazonaws.com to publish
  5. Scaled ASG to desired=1 โ€” instance launched
  6. Email received at onwuabus@gmail.com with full event JSON payload including instance ID, subnet, AZ, cause, and timestamps

Email payload confirmed:

{
  "detail-type": "EC2 Instance Launch Successful",
  "source": "aws.autoscaling",
  "detail": {
    "AutoScalingGroupName": "dop-lab-asg",
    "EC2InstanceId": "i-0a160351f94acc722",
    "Cause": "a user request update...increasing the capacity from 0 to 1"
  }
}

Common exam scenarios:

“Notify team when CodePipeline fails” โ†’ EventBridge (pipeline state change FAILED) โ†’ SNS โ†’ email

“Stop dev instances every night at 10pm” โ†’ EventBridge scheduled rule cron(0 3 * * ? *) โ†’ Lambda โ†’ ec2:StopInstances

“Auto-remediate non-compliant Config resources” โ†’ AWS Config rule โ†’ EventBridge โ†’ SSM Automation

“Trigger runbook when ASG launches instance” โ†’ EventBridge (EC2 Instance Launch Successful) โ†’ SSM Automation

Rule creation runbook:

# Create rule
aws events put-rule \
  --name <rule-name> \
  --event-pattern '<json-pattern>' \
  --state ENABLED

# Wire target
aws events put-targets \
  --rule <rule-name> \
  --targets "Id=1,Arn=<target-arn>"

# Add SNS resource policy for EventBridge
aws sns set-topic-attributes \
  --topic-arn <topic-arn> \
  --attribute-name Policy \
  --attribute-value '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"events.amazonaws.com"},"Action":"sns:Publish","Resource":"<topic-arn>"}]}'

# Verify rule
aws events describe-rule --name <rule-name> --output table

Engineering Analogy

EventBridge pattern rules are the AWS equivalent of systemd socket activation or inotify watches โ€” something happens (a file changes, a socket receives a connection, an AWS service emits an event) and a handler fires immediately without polling. The difference is EventBridge operates at the AWS control plane level, reacting to infrastructure events across your entire account.


Best Practices


Common Mistakes


Pro Tip

When EventBridge โ†’ SNS delivery fails silently, check two things in order: (1) SNS topic resource policy for events.amazonaws.com, (2) EventBridge rule’s FailedInvocations CloudWatch metric. The resource policy is the most common miss and produces no visible error on the rule itself.


Key Takeaways


Related Articles


References

System Context

โ† Back to Kb