How to Detect and Shutdown an Unused AWS EC2 Instance

How to Detect and Shutdown an Unused AWS EC2 Instance

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.

1. Go to the AWS Console and enter the EC2 dashboard. Select “Instances? or “Running Instances?.

2. Select the instance for which the action will be set. Go to the monitoring tab of the instance details.

3. From the “Actions? menu, click on the “Add / Edit Alarms? button or the “Create Alarm? button.

4. Provide the Notification name (SNS topic name), the Alarm name, and the recipient who will receive the email on alert as well action. The current action states the “Stop? instance when the alert is triggered. Define the criteria for alert creation, such as the Cloudwatch metric and the criteria (when CPU utilization is < 5%). Define the period. For example, the user can state that for a consecutive 15 periods (each of 10 Minutes) the usage should be less than 5%. Click on the “Create Alarm? button.

5. Once the alarm has been created, AWS will show the confirmation message. Click on the Alarm name to view more details.

6. The AWS Cloudwatch console shows the alarm details.

7. AWS will send the email to subscribe to the alert. Click on “Confirm Subscription? to subscribe for the alert.

8. When the actual usage of the instance is less than 5% for a consecutive 150 minutes (15 periods each of 10 minutes), AWS will send a couple of emails as an alert.

9. The Cloudwatch will trigger the stop instance action on creation of the alert.

10. Once the action has been completed, the instance will be stopped.

Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, Cloud Monitoring, CloudWatch, CloudWatch Alarm, AWS Scheduled Events, AWS SNS, Cloud Utilization

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!

Hitchhiker's Guide to The Cloud

Newvem's eBook for Cloud Operations