How do I monitor automatic recovery of my EC2 instances using CloudWatch alarms and SNS?
Last updated: 2019-03-12
I want to configure automatic recovery for my Amazon Elastic Compute Cloud (Amazon EC2) instances. How do I monitor these automatic recovery actions using Amazon CloudWatch (CloudWatch) and Amazon Simple Notification Service (Amazon SNS)?
You can configure a CloudWatch alarm to automatically recover impaired Amazon EC2 instances and notify you through Amazon SNS. However, the SNS notification by itself doesn't include the results of the automatic recovery action.
You must also configure a CloudWatch Events rule to monitor AWS Personal Health Dashboard (AWS Health) events for your instance. Then, you are notified of the results of automatic recovery actions for an instance.
Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.
First, create a CloudWatch alarm for your Amazon EC2 instances.
- For Send notification to, enter your SNS topic name.
- For Take the action, choose Recover.
For more information, see How can I set up a CloudWatch alarm to automatically recover my EC2 instance?
Then, configure CloudWatch Events to monitor the following AWS Health events. For Target, choose the SNS topic you created.
You can also use the AWS CLI to list the AWS Health events associated with EC2 instance automatic recovery. Use the command describe-event-types with the appropriate --region as follows:
$ aws health describe-event-types --filter services=EC2 --query eventTypes.code --region us-east-1 | grep AUTO_RECOVERY "AWS_EC2_INSTANCE_AUTO_RECOVERY_FAILURE", "AWS_EC2_INSTANCE_AUTO_RECOVERY_NO_ACTION", "AWS_EC2_INSTANCE_AUTO_RECOVERY_SUCCESS",
Automatic recovery results are then emailed to both your AWS account's main contact and alternate contact. Look for email subject lines similar to:
- [Auto Recovery] Amazon EC2 instance recovery: Success
- [Auto Recovery] Amazon EC2 instance recovery: No action taken
- [Auto Recovery] Amazon EC2 instance recovery: Failure