- Create an SNS topic (
ec2-alerts) and subscribe an endpoint. - Create a Lambda function (
ec2-event-handler) to receive EventBridge events. - Build an EventBridge rule (Advanced Builder) that matches EC2
stoppedevents. - Add both SNS and Lambda as rule targets.
- Generate a test event by stopping an EC2 instance and verify delivery.
Useful references:
1 — Create the SNS topic
Open the Amazon SNS console and create a topic to receive published events.
- Console: Topics → Create topic.
- Choose Standard (FIFO ordering is not required for this demo).
- Name the topic (example:
ec2-alerts). - Keep other settings default unless you require encryption, delivery retries, or custom access control.

2 — Create the Lambda function
Create a basic Lambda function that will be invoked by EventBridge.
- Lambda console → Create function → Author from scratch.
- Function name:
ec2-event-handler(or your preferred name). - Runtime: Python 3.9+ (choose the supported runtime available in your account).
- Permissions: leave defaults (Lambda creates an execution role automatically).
- Create the function. You can add processing code later; for testing, the default handler that logs the event is sufficient.
3 — Create the EventBridge rule (Advanced Builder)
EventBridge receives AWS service events on thedefault event bus. Create a rule to filter EC2 state-change events and route them to SNS and Lambda.

- EventBridge console → Event buses → select
default. - Create rule → choose the Advanced Builder so you can view/edit the JSON event pattern.
- Name:
ec2-state-change - Event bus:
default - Enabled: Yes (so it starts processing immediately)

- Event source: AWS events
- Service name: EC2
- Event type: EC2 Instance State-change Notification
- Filter for the
stoppedstate
4 — Configure targets: SNS and Lambda
Add both targets to the rule so a single matching event is delivered to multiple endpoints.
- Add target #1:
- Target type: AWS service → SNS topic
- Select:
ec2-alerts - Allow EventBridge to create the default role (it grants permission to publish to SNS)
- Add target #2:
- Target type: AWS service → Lambda function
- Select:
ec2-event-handler - Allow EventBridge to create/use the role for invoking Lambda
5 — Subscribe an endpoint to the SNS topic
To receive notifications, subscribe an endpoint (for example, an email address) to the SNS topic.
- Open the
ec2-alertstopic → Subscriptions → Create subscription. - Topic ARN: e.g.,
arn:aws:sns:us-east-2:635573991785:ec2-alerts - Protocol: Email (or Email-JSON, HTTPS, SMS, etc.)
- Endpoint: your email address
- Create the subscription; SNS sends a confirmation message to the endpoint.


6 — Generate a test event: stop an EC2 instance
Trigger a real EC2 state-change event by stopping an EC2 instance in the same account and region as your EventBridge rule. Steps:- Ensure you have a running EC2 instance in the same region/account.
- Stop the EC2 instance (Actions → Instance State → Stop).
- EC2 emits a state-change notification which is placed on the
defaultEventBridge bus.
stopped event is emitted, EventBridge evaluates the event against your rule’s JSON pattern. If it matches, the rule routes the event to both the SNS topic and the Lambda function.
Sample event delivered by EventBridge:
7 — Verify delivery
-
Lambda:
- Open the
ec2-event-handlerfunction → Monitor tab. - View invocation metrics and CloudWatch Logs to confirm the function executed and to inspect the raw event payload.
- Open the
-
SNS (email):
- Check the subscribed email inbox for the notification message.
- The message should contain instance ID, account, and the EC2 Instance State-change Notification details.
- EC2 emits an instance state-change event.
- The event is sent to the EventBridge
defaultevent bus. - The
ec2-state-changerule filters forstate: stopped. - Matching events are routed to multiple targets: SNS (
ec2-alerts) and Lambda (ec2-event-handler). - SNS delivers to subscribers and Lambda runs your processing code.
Make sure your Lambda’s execution role has appropriate permissions if you intend to process or publish messages from within the function. For basic invocation testing, the automatic role created by Lambda is usually sufficient. If your function needs to publish to SNS, write to other AWS services, or access resources, add those permissions explicitly to the execution role.