Amazon CloudWatch is used to monitor several AWS products. Cloudwatch provides various metrics to monitor the user’s instance, the resources as well as the AWS billing. Cloudwatch can send a notification about a particular event. The user can create alerts to send the notifications. CloudWatch monitors the CPU usage and sends a notification if the usage exceeds the specified threshold. AWS CloudWatch also offers a unique feature to stop or terminate an instance when the CloudWatch alarm is triggered.
The present guide demonstrates how to stop an instance if the EC2 instance is not in use. The alarm will be configured to stop the instance when the CPU usage is less than 5% for more than 2 hours. The below mentioned steps are only for an EBS backed instance. For an instance store backed AMI instance, the user can configure the terminate action only.