Wondering how to get email notifications when EC2 instance changes states? We can help you with this!
As a part of our AWS Support Services, we often receive similar requests from our AWS customers.
Today, let’s see the steps followed by our Support Techs to help our customers to get email notifications.
Email notifications when EC2 instance changes states
By default, we don’t get a lot of visibility into how our instances are behaving when managing a large number of EC2 instances. Any monitoring beyond what we get in the console needs to be configured and set up by the AWS user using services like CloudWatch.
AWS CloudWatch allows us to create rules which will publish to an SNS topic any time an EC2 instance has a state change. We can subscribe to emails to this SNS topic and receive emails anytime there’s a new SNS publication.
Here, for receiving email notifications when our EC2 instance changes states:
- We need to create an Amazon SNS topic and this SNS topic sends messages to subscribing endpoints.
2. Then we need to create an Amazon CloudWatch event using the EC2 Instance State-change Notification event type.
Now, let’s discuss the steps in detail for creating an Amazon SNS topic and Amazon CloudWatch event:
Creating an Amazon SNS topic
- Log in to the AWS Management console and then open the Amazon SNS console.
2. Select Topic and then select Create topic.
3. Enter a name for the topic for the option Name.
4. Enter a name for the topic for the option Display name.
5. Then click Create topic.
6. Select Create subscription on the Subscriptions tab.
7. Select Email for Protocol and enter the email address where we want to receive the notifications for the option Endpoint.
8. Select Create subscription.
9. Then we will receive a subscription confirmation email and select Confirm subscription.
10. Now note the SNS topic that we created as we need to use this topic when creating the CloudWatch event rule.
Creating a CloudWatch event
- Firstly log in to the AWS Management console and then open the CloudWatch console.
2. Now select Events and then select Get started.
3. Select the following:
Firstly, Select Event Pattern for Event Source.
Select EC2 for Service Name.
Then select EC2 Instance State-change Notification for Event Type.
Then select Any state and Any instance.
4. Now select Add target.
5. We need to select the SNS topic and then select the topic name that we created earlier for the Topic.
6. Select Input Transformer for Configure input.
7. Enter the following for the Input Path:
{“instance-id”:”$.detail.instance-id”, “state”:”$.detail.state”, “time”:”$.time”, “region”:”$.region”, “account”:”$.account”}
8. Enter the following for the Input template:
“At <time>, the status of your EC2 instance <instance-id> on account <account> in the AWS Region <region> has changed to <state>.”
9. Select Configure details and enter a rule name for Name and enter a rule description for Description.
10. Select Create rule.
We can test the rule by starting or stopping an instance. This rule generates an email notification every time an instance changes to any state.
[Need help with more AWS queries? We’d be happy to assist]
Conclusion
To conclude, today we discussed the steps followed by our Support Engineers to help our customers to get email notifications when EC2 instance changes states.
0 Comments