DEV Community

Jaira Encio for AWS Community ASEAN

Posted on • Updated on

Setting up Email Notification for EC2 instance changes using Amazon SNS and Eventbridge

Output: To receive email notif everytime your EC2 instances changes its status. (Terminated, Stopped, etc)

What is Amazon SNS?
Amazon SNS enables you to send notifications directly to your customers.

What is Amazon EventBridge?
Amazon EventBridge is a serverless event bus that makes it easier to build event-driven applications at scale using events generated from your applications, integrated Software-as-a-Service (SaaS) applications, and AWS services.


  1. Setup SNS topic
  2. Create email subscription on topic
  3. Setup EC2 Instance State-change Notification eventbridge rule

Setting up SNS topic and email subscription

1. Go to AWS SNS console, and then choose Topics from the navigation pane.

2. Select Create topic.

Create topic
For the type, I would be selecting Standard. Then just enter name and display name for your topic.

3. Click Create topic.

Topic created

4. On the Subscriptions tab, click Create subscription.

Create Subscription

For Protocol, select Email.
For Endpoint, enter the email address where you want to receive the notifications.

If you want to change this to a SMS notif, you can simple select SMS for protocal then enter mobile number on endpoint where you want to receive notifications.

5. Click Create subscription.

subscription created

6. Confirm email subscription sent to the email address you entered.

email confirmation

subscription confirmed

7. Go to your topic then check email status.

status confirmed

It should show that your email is now confirmed.

Setting up EC2 TerminateInstances eventbridge rule

1. Open the EventBridge console, and then click Create Rule


2. Fill up details on define rule detail then click next

Create rule

Enter a Name and description for your rule.
On rule type, select rule with an event pattern

3. Fill up details on Build event pattern then click next

Image description
Image description
For Service provider, choose AWS.
For Service name, choose EC2.
For Event type, choose EC2 Instance State-change Notification.

4. Fill up select targets then click next

In Select targets, choose SNS topic from the Target dropdown list.
For Topic, choose the topic name that you created earlier.

5. Click Create rule

You can test this rule by terminating your instance. This rule generates an email notification every time an instance is terminated. You can select other states as well.


email notif terminated

Discussion (0)