0
0
AWScloud~10 mins

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

Choose your learning style9 modes available
Process Flow - CloudWatch Events (EventBridge)
Event Occurs
EventBridge Receives Event
Match Event to Rule?
NoDiscard 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.