AWS Logo
Menu
Optimize AWS Costs: Auto-Shutdown for EC2 Instances

Optimize AWS Costs: Auto-Shutdown for EC2 Instances

Published Mar 3, 2025
To stay efficient and continue delivering their mission, organizations constantly look for ways to cut IT costs without sacrificing service quality. One key area for potential savings is cloud resource management, particularly with Amazon Elastic Compute Cloud (Amazon EC2) instances. Many organization end up with unexpected expenses when EC2 instances are left running during off-peak hours or periods of low usage.In this post, I discuss how one can achieve this using :-
Using Amazon CloudWatch alarms to dynamically shut down instances based on inactivity.
This approach is perfect for automating instance management based on usage patterns. It offers precise control over shutdown conditions, allowing you to optimize resource consumption and reduce costs dynamically. By tracking periods of inactivity, CloudWatch alarms can automatically power down idle instances, ensuring efficient utilization of resources within your AWS environment especially in Pre-prod (Staging) Environment
 

Step 1: Find your EC2 instance

To find your EC2 instance and create a CloudWatch alarm, follow these steps:
  1. On the Amazon EC2 console, select the instance you want to automatically shut down.
  2. Choose the + icon in the Alarm status column to create a CloudWatch alarm, as shown in the following screenshot.

Step 2: Create a CloudWatch alarm

To create a CloudWatch alarm to automatically stop the instance when its CPU utilization remains at or below 3 percent for 1 hour, indicating inactivity, set the following on the Manage CloudWatch alarms page:
  1. Choose Create an alarm.
  2. (Optional) Enable Alarm notification and configure an Amazon Simple Notification Service (Amazon SNS) topic to receive alarm notification.
  3. Enable Alarm action and choose Stop.
  4. In the Alarm thresholds section, configure:
– In Group samples by, choose Average
– In Type of data to sample, choose CPU Utilization.
– In Alarm when, choose <=
– In Percent, choose 3
– In Consecutive period, choose 1
– In Period, choose 1 Hour
– Name your alarm (for example, AutoShutdownInstance).
– Enter an alarm description.
  1. Choose Create.
Values to enter when creating the alarm
One potential risk of configuring a CloudWatch alarm to automatically shut down instances is the possibility of stopping instances that are engaged in critical background tasks with low CPU usage. To avoid this issue, it is important to thoroughly review the workload patterns of your instances before implementing an automatic shutdown mechanism. Consider incorporating additional metrics beyond CPU utilization, such as network activity or custom application metrics, to gain a more comprehensive understanding of instance activity.
 

Comments