Amazon Elastic Compute Cloud (EC2) is a cloud infrastructure service that makes it easy to deploy systems running Linux, Windows, and even MacOS. EC2 is one of the oldest services in the AWS cloud platform, dating back to a 2006 beta release, according to Wikipedia.
There are many different “sizes” of EC2 instances that you can deploy, with varying attributes including virtual CPUs, memory, temporary storage, network performance, and more. AWS regularly releases new generations of EC2 instance families (ie. c7, m7), based on new CPU architectures, providing more performance-per-watt consumed.
Amazon CloudWatch is a monitoring service that tracks many useful metrics, including consumption of CPU and memory for Amazon EC2 instances. By default, when you deploy Amazon EC2 instances, the CloudWatch service captures periodic measurements of EC2 utilization.
When you’re selecting an EC2 instance size for deployment, you generally need to estimate, or measure, the resource consumption of your workloads, under varying load conditions. Once you’ve deployed an application to an EC2 instance, it stays running virtually indefinitely, unless you intentionally make changes to the EC2 instance configuration.
AWS allows you to stop an on-demand EC2 instance, resize it, and then restart it with a different set of allocated resources. This technique is generally known as “vertical scaling” either up or down, however it does require workload downtime.
You can schedule periodic scaling events for predictable workloads, to increase or decrease the size of your EC2 instances, if vertical scaling is a requirement. For example, if you know that a particular EC2 instance will be under heavy load from 8 AM to 4 PM every day, you could schedule a scale-up event at 7:50 AM, and a scale-down event at 4:10 PM. Amazon EventBridge allows you to create scheduled events, which could trigger an AWS Lambda function or Step Functions workflow, which resizes your EC2 instance.
The details of setting this up are beyond the scope of this article, but feel free to investigate this technique in more detail.
Stratusphere™ FinOps identifies underutilized Amazon EC2 instances across your entire AWS Organization, including multiple AWS accounts and regions. Navigating all of this data manually, in the AWS Management Console, can require a significant level of effort. Instead, Stratusphere™ FinOps displays this data in an aggregated, and easy-to-consume format.
Under the Findings section in Stratusphere™ FinOps, you can apply various filters to narrow down which cost savings opportunities are displayed. In the screenshot below, you can see that we’ve filtered to a specific company in our organization, and further filtered to Amazon EC2.
In the Stratusphere™ FinOps user interface, one of the available cost optimization findings that can be triggered will say “Low Utilization Amazon EC2 Instances.” In these cases, there will be a corresponding AWS resource ID that indicates the exact EC2 instance that the low utilization was discovered on.
Per the AWS Trusted Advisor documentation, EC2 instances are flagged as underutilized when CPU utilization falls under 10% and network I/O is under 5 MB, for a four-day period. This resource ID can vary between cloud platforms; on AWS, it is an Amazon Resource Name (ARN). Effectively, this finding means that the EC2 instance has more CPU & memory resources allocated to it than the workload running on the EC2 instance actually requires.
If you’re interested in leveraging Stratusphere™ FinOps and onboarding your organization, please reach out to the StratusGrid sales team.
Now that you’ve identified the low-utilization EC2 instances, it’s time to apply the appropriate optimization technique. In this case, we’ll be resizing the EC2 instance to a smaller instance type, with fewer virtual CPUs and less memory allocated.
Before you resize your EC2 instance, you’ll want to determine which instance type you should switch to. You can find the configuration details for each EC2 instance type in the Amazon EC2 On-Demand Pricing page.
To remediate this finding manually, you can follow the steps below.
NOTE: You cannot currently resize EC2 instances that have been launched using the spot pricing model. In these circumstances, the Change Instance Size option will be grayed out. If you’re using the AWS CLI, you’ll receive an error message similar to the following: “An error occurred (UnsupportedOperation) when calling the ModifyInstanceAttribute operation: Modifying 'instanceType' is not supported for spot instances.”
There are several considerations to keep in mind when evaluating and executing EC2 instance resizing operations:
You can use automation tools for AWS, such as the AWS CLI or AWS PowerShell module, to resize EC2 instances. There are several commands you’ll need to run, in order to stop, resize, and start each EC2 instance. The API call that actually modifies the EC2 instance type is called ModifyInstanceAttribute.
aws ec2 stop-instances --instance-ids i-0000000
aws ec2 modify-instance-attribute --instance-id i-0000000 --instance-type c7i.large
aws ec2 start-instances --instance-ids i-0000000
If you do not have a default region set, you can also specify the region that you’re operating against, by using the --region parameter.
You can use the AWS EC2 module for PowerShell to automate the EC2 resizing commands.
$InstanceId = 'i-000000'
Stop-EC2Instance -InstanceId $InstanceId
Edit-EC2InstanceAttribute -InstanceId $InstanceId -InstanceType c7i.large
Start-EC2Instance -InstanceId $InstanceId
You can save large amounts of potential spend, across your entire AWS Organization, by identifying low utilization EC2 instances with Stratusphere™ FinOps, and resizing them to a smaller size. The effort required to resize an EC2 instance is relatively low, making it an easy way to reduce your monthly cloud spend.
For low-utilization applications, you may want to consider modernizing your architecture. Using a container or serverless deployment model can simplify deployment and give you even more granularity around compute resource consumption. StratusGrid can consult with you to strategize and implement a modernized architecture for your cloud workloads. Contact us today for more information.
BONUS: Download Your FinOps Guide to Effective Cloud Cost Optimization Here ⤵️