Trigger Event Notification by Harsh Patel

Using CloudWatch and SNS to trigger event notification

Being aware of your current state of mind is very important! So doesn’t it make sense to be aware of your current state of cloud services as well? Think about it, What if any of your cloud service went down due to increase in load or network traffic increase or state of any of your resource changes during an Sunday evening? I don't mean to interrupt your Sunday experience but surely you need to be notified regarding the issue and need to quickly fix it before it disrupts your entire infrastructure severely.

Let’s learn how to get notified when an EC2 Instance changes it State using CloudWatch and SNS (Simple Notification Service). Let’s dive into it!

How it’s done?

  1. You create an event on CloudWatch to monitor the state of your EC2 Instance and trigger an event notification
  2. You create a SNS topic with your preferred Endpoint (Phone, Email Address, etc.) to be notified
  3. You get notified on your Endpoint device about the change in the state of your EC2 Instance

Let’s first create an SNS Topic and Subscription, so we have an topic to select during creation of CloudWatch event

  1. Go to Amazon SNS (Simple Notification Service) > Topics > Create topic
Create an SNS Topic

2. Enter the Topic Type and Name of the Topic

We’ll use a Standard Type here to be able to receive the notification via an SMS

Entering the SNS Topic details

3. Now, we need to Create subscription with details of our Endpoint

Create subscription

4. Select the Protocol (SMS, Email, etc.), I want to be notified via SMS that’s why I’ll be selecting SMS. Lastly enter your Endpoint (Mobile Number in our case)

Enter Endpoint details

Note: If you are not able to select your preferred Endpoint from a drop-down list or if you don’t see any registered/verified Endpoint (Mobile Number). You might need to register and verify one using below process

Register and verify your Mobile Number

Add a Phone Number (Register and verify), Once done you’ll be able to see the number marked as verified and listed with other numbers (if present)

Add a phone number

Now Let’s create a CloudWatch event to monitor the state of our EC2 Instance and notify us.

  1. We need a Rule to be created, to do that go to
    CloudWatch > Events > Rules
Create a Rule

2. Enter the Service Name and Event Type

Select Service Name and Event Type

3. Select the state for which you want to be notified and the Instance on which the rule is to be applied (you may select any instance to be notified for all Instances)

State and Instance details

4. Add an Target (an SNS Topic to be notified)

Add an Target

5. Configure rule details, Add Name and description then click on Create rule

Configuring rule details

Once the rule is created it will be listed under rule list

Rule created and listed

All done! Let’s test it.

  1. Right now, my Instance is in Running state. I’ll stop my instance and see if it notifies me.

Yup! received SMS notification on my mobile with the current state of the EC2 Instance ( Running to Stopped)

EC2 Stopped Notification

2. Let’s Start the Instance and see if we receive the notification

Yes! receiving SMS Notification for that too

EC2 Running Notification

That’s how you can use CloudWatch and SNS to get notified for any event for your preferred service. You may also configure different Endpoint to receive notification like Email, SQS, HTTP/HTTPS, etc.

Now go back to your movie and enjoy your Weekend! AWS will notify you if something is fishy 😉

I am an Rookie scaling vertically as an Veteran. Learning Cloud and DevOps technologies because “It ran on my machine” excuse doesn’t work anymore.