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.
Overview
- Setup SNS topic
- Create email subscription on topic
- 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.
For the type, I would be selecting Standard. Then just enter name and display name for your topic.
3. Click Create topic.
4. On the Subscriptions tab, click 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.
6. Confirm email subscription sent to the email address you entered.
7. Go to your topic then check email status.
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
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
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.
Top comments (0)