Bird
Raised Fist0
AWScloud~10 mins

CloudWatch Events (EventBridge) in AWS - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - CloudWatch Events (EventBridge)
Event Occurs
↓
EventBridge Receives Event
↓
Match Event to Rule?
No→Discard Event
Yes↓
Send Event to Target(s)
↓
Target Executes Action
Events happen and are sent to EventBridge. EventBridge checks rules to find matches. If matched, it sends the event to targets which then act on it.
Execution Sample
AWS
rule = {
  "EventPattern": {"source": ["aws.ec2"]},
  "Targets": [{"Id": "1", "Arn": "arn:aws:lambda:..."}]
}

# EventBridge receives event from EC2 instance
# Rule matches event source
# Target Lambda function invoked
This setup listens for EC2 events and triggers a Lambda function when such an event occurs.
Process Table
StepEvent ReceivedRule Match CheckMatch ResultAction Taken
1{"source":"aws.ec2","detail-type":"EC2 Instance State-change Notification"}Check if source is 'aws.ec2'YesSend event to Lambda target
2{"source":"aws.s3","detail-type":"Object Created"}Check if source is 'aws.ec2'NoDiscard event
3{"source":"aws.ec2","detail-type":"EC2 Instance Launch"}Check if source is 'aws.ec2'YesSend event to Lambda target
4No new eventN/AN/AStop processing
💡 No new event to process, execution stops
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
eventNone{"source":"aws.ec2","detail-type":"EC2 Instance State-change Notification"}{"source":"aws.s3","detail-type":"Object Created"}{"source":"aws.ec2","detail-type":"EC2 Instance Launch"}None
rule_matchFalseTrueFalseTrueN/A
actionNoneInvoke LambdaDiscardInvoke LambdaStop
Key Moments - 2 Insights
Why does the event with source 'aws.s3' get discarded?
Because the rule only matches events where the source is 'aws.ec2' as shown in execution_table row 2 where the match result is No and action is Discard.
What happens when an event matches the rule?
When the event matches the rule (source is 'aws.ec2'), EventBridge sends the event to the target, which in this example is a Lambda function, as shown in rows 1 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the action taken at step 2?
AInvoke Lambda function
BDiscard event
CSend event to S3
DNo action
💡 Hint
Check the 'Action Taken' column in row 2 of the execution_table
At which step does the event source 'aws.ec2' trigger the Lambda target?
AStep 2
BStep 4
CStep 1 and Step 3
DStep 3 only
💡 Hint
Look at the 'Event Received' and 'Action Taken' columns for steps with source 'aws.ec2'
If the rule was changed to match source 'aws.s3', what would happen at step 1?
AEvent would be discarded
BEvent would trigger Lambda
CNo change, event discarded
DEventBridge would error
💡 Hint
Refer to how rule matching works in execution_table and variable_tracker
Concept Snapshot
CloudWatch Events (EventBridge) listens for events from AWS services.
Rules define which events to catch based on patterns like source.
When an event matches a rule, EventBridge sends it to targets (Lambda, SQS, etc).
If no match, event is discarded.
This enables automated responses to AWS events.
Full Transcript
CloudWatch Events, also called EventBridge, works by receiving events from AWS services or custom sources. It checks each event against rules that specify patterns to match, such as the event source. If the event matches a rule, EventBridge forwards it to one or more targets, like Lambda functions, which then perform actions. If the event does not match any rule, it is discarded. This process allows automatic reactions to changes or actions in your AWS environment without manual intervention.

Practice

(1/5)
1. What is the primary purpose of AWS CloudWatch Events (EventBridge)?
easy
A. To create virtual servers in the cloud
B. To store large amounts of data for analysis
C. To manage user permissions and access
D. To automatically respond to events by triggering actions

Solution

  1. Step 1: Understand EventBridge role

    EventBridge watches for events happening in AWS or custom apps and triggers actions automatically.
  2. Step 2: Compare options

    Virtual servers relate to EC2, data storage to S3, user permissions to IAM; only responding to events matches EventBridge.
  3. Final Answer:

    To automatically respond to events by triggering actions -> Option D
  4. Quick Check:

    EventBridge triggers actions on events = C [OK]
Hint: EventBridge links events to actions automatically [OK]
Common Mistakes:
  • Confusing EventBridge with storage or compute services
  • Thinking it manages user permissions
  • Assuming it creates servers
2. Which of the following is the correct JSON snippet to create a CloudWatch Events rule that triggers every 5 minutes?
easy
A. {"ScheduleExpression": "rate(5 minute)"}
B. {"ScheduleExpression": "cron(0/5 * * * ? *)"}
C. {"ScheduleExpression": "rate(5 min)"}
D. {"ScheduleExpression": "cron(5 * * * ? *)"}

Solution

  1. Step 1: Understand schedule syntax

    EventBridge supports rate and cron expressions. For 5-minute intervals, cron syntax is cron(0/5 * * * ? *).
  2. Step 2: Check each option

    {"ScheduleExpression": "rate(5 minute)"} uses rate(5 minute) which is invalid syntax (must use 'minutes' plural). {"ScheduleExpression": "cron(0/5 * * * ? *)"} uses correct cron syntax for every 5 minutes. {"ScheduleExpression": "rate(5 min)"} uses 'min' which is invalid. {"ScheduleExpression": "cron(5 * * * ? *)"} triggers at minute 5 every hour, not every 5 minutes.
  3. Final Answer:

    {"ScheduleExpression": "cron(0/5 * * * ? *)"} -> Option B
  4. Quick Check:

    Cron for every 5 minutes = D [OK]
Hint: Use cron(0/5 * * * ? *) for every 5 minutes [OK]
Common Mistakes:
  • Using 'min' instead of 'minutes' in rate expressions
  • Confusing cron syntax for intervals
  • Using rate with incorrect pluralization
3. Given this EventBridge rule JSON snippet, what will happen when an EC2 instance state changes to 'stopped'?
{
  "Source": ["aws.ec2"],
  "DetailType": ["EC2 Instance State-change Notification"],
  "Detail": {"state": ["stopped"]}
}
medium
A. The rule triggers only when an EC2 instance stops
B. The rule triggers for any EC2 state change
C. The rule triggers only when an EC2 instance starts
D. The rule never triggers

Solution

  1. Step 1: Analyze event pattern

    The pattern filters events from source 'aws.ec2' with detail type 'EC2 Instance State-change Notification' and detail state 'stopped'.
  2. Step 2: Understand filtering effect

    Only events where the instance state changes to 'stopped' match this pattern, so the rule triggers only then.
  3. Final Answer:

    The rule triggers only when an EC2 instance stops -> Option A
  4. Quick Check:

    Detail state filter 'stopped' triggers only on stop = A [OK]
Hint: Detail filters limit triggers to specific event states [OK]
Common Mistakes:
  • Assuming all EC2 state changes trigger the rule
  • Confusing 'stopped' with 'started' state
  • Ignoring the detail filter in the event pattern
4. You created an EventBridge rule to trigger a Lambda function on S3 object creation, but the Lambda never runs. What is the most likely cause?
medium
A. The rule's event pattern does not match S3 object creation events
B. The Lambda function has no code
C. S3 does not support EventBridge integration
D. The Lambda function is in a different AWS region

Solution

  1. Step 1: Check EventBridge and S3 integration

    S3 supports EventBridge events for object creation, so integration is possible.
  2. Step 2: Verify event pattern correctness

    If the event pattern does not correctly specify S3 object creation events, the rule won't trigger the Lambda.
  3. Step 3: Consider Lambda region

    EventBridge and Lambda must be in the same region; cross-region triggers do not work.
  4. Final Answer:

    The rule's event pattern does not match S3 object creation events -> Option A
  5. Quick Check:

    Incorrect event pattern blocks trigger = B [OK]
Hint: Check event pattern matches actual event source and type [OK]
Common Mistakes:
  • Assuming Lambda runs without correct event pattern
  • Ignoring region mismatch issues
  • Believing S3 can't send events to EventBridge
5. You want to create an EventBridge rule that triggers a Lambda function only when an EC2 instance is launched in a specific VPC. Which approach correctly achieves this?
hard
A. Use an event pattern filtering on 'source' as 'aws.ec2' and 'detail-type' as 'EC2 Instance State-change Notification' with 'detail.vpc-id' matching the VPC ID
B. Use a scheduled rule to check EC2 instances every minute and invoke Lambda if any are in the VPC
C. Use an event pattern filtering on 'source' as 'aws.ec2' and 'detail-type' as 'EC2 Instance Launch Successful' with 'detail.vpc-id' matching the VPC ID
D. Use an event pattern filtering on 'source' as 'aws.ec2' and 'detail-type' as 'EC2 Instance State-change Notification' with 'detail.state' as 'running'

Solution

  1. Step 1: Identify correct event type for instance launch

    The event 'EC2 Instance Launch Successful' signals a new instance launch, not state changes.
  2. Step 2: Filter by VPC ID in event detail

    Filtering on 'detail.vpc-id' ensures only instances in the specific VPC trigger the rule.
  3. Step 3: Evaluate other options

    State-change notification with VPC ID does not indicate launch specifically. Scheduled polling is inefficient. State-change to running filters state but not launch event.
  4. Final Answer:

    Use an event pattern filtering on 'source' as 'aws.ec2' and 'detail-type' as 'EC2 Instance Launch Successful' with 'detail.vpc-id' matching the VPC ID -> Option C
  5. Quick Check:

    Launch event + VPC filter = A [OK]
Hint: Filter on launch event and VPC ID in event detail [OK]
Common Mistakes:
  • Using state-change events instead of launch events
  • Trying scheduled polling instead of event-driven
  • Ignoring VPC ID filter in event pattern
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard