AWS EC2 instance state change notification
This documentation is based on this guide.
Step 1: Create an SNS topic. Skip if you want to reuse an existing topic.
Go to AWS Simple Notification Service (SNS).
Navigate to Topics and click Create topic button.
Create a topic with the following info-
Type: Standard.
Name: give it a name
Click: Create topic button. The topic details page will be opened.
Open the subscriptions tab and click Create Subscription
Create a subscription with the following info-
Protocol: Email
Endpoint: Your email
Click: Create subscription button.
You’ll get an email with the subject: AWS Notification - Subscription Confirmation
Click: Confirm Subscription link from the email.
Topic creation is completed.
Step 2: Create a CloudWatch event
Open the CloudWatch console.
Navigate to the Events > Rules, and click the Create rule button.
Create rule form has two sections. Event source, and Targets.
Specify Event Source with the following info-
Source: Event Pattern.
Service Name: EC2.
Event Type: EC2 Instance State-change Notification.
Select Any State, or specific state(s) and do specify.
Select Any Instances, or Specific Instance Id(s) and add instance-ids.
Click the Add target button and add a target with the following info
From the targets dropdown, select SNS topic.
From the topic dropdown, select the topic just created in the first step.
From Configure input, select Input Transformer.
Input path: {"instance-id":"$.detail.instance-id", "state":"$.detail.state", "time":"$.time", "region":"$.region", "account":"$.account"}
Input template: "At <time>, the status of your EC2 instance <instance-id> on account <account> in the AWS Region <region> has changed to <state>."
Click Configure details button. Configure rule details form will open.
Fill the form with a name and state=Enabled.
Save clicking the Create rule button.
The alarm has been created.