How can I set up a CloudWatch alarm to automatically recover my EC2 instance?
Last updated: 2021-03-23
I want to set up automatic recovery of an Amazon Elastic Compute Cloud (Amazon EC2) instance using Amazon CloudWatch. How can I do this?
If your instance fails a system status check, you can use CloudWatch alarm actions to automatically recover your instance. The recover option is available for over 90% of deployed Amazon EC2 instances. However, the recover option works only for system check failures, not for instance status check failures. In addition, if you terminate your instance, then it can't be recovered.
If your instance fails a status check, you might need to reboot the instance or change the configuration. For more information, see Types of status checks.
- Open the Amazon EC2 console.
- In the navigation pane, choose Instances.
- Select the instance that you want to configure.
- Choose Actions, and then choose Monitor and troubleshoot. Then, choose Manage CloudWatch alarms.
- Choose Create an alarm.
Note: To create an alarm, you must have AWS Identity and Access Management (IAM) permissions to stop and start the associated instance. For more information, see Creating IAM roles.
- For Alarm notification, choose an existing Amazon Simple Notification Service (Amazon SNS) topic. To create a new topic, see Creating an Amazon SNS topic.
Note: To receive notifications when an alarm is triggered, you must be subscribed to the SNS topic.
- Toggle on Alarm action, and then choose Recover.
- For Group samples by and Type of data to sample, choose an appropriate statistic and metric for your use case.
- For Consecutive period and Period, specify the evaluation period for the alarm.
- (Optional) Modify the automatically created Alarm name.
- Choose Create.