7 Ways to Save Costs on Amazon EC2 Instances
When creating Amazon EC2 instances, you can choose from 28 types depending on your budget and needs. Here are seven ways to significantly cut your Amazon EC2 costs.
April 26, 2021
If your organization uses the Amazon cloud, Amazon EC2 costs are probably a large part of your cloud bill. In this article, I explain the basics of EC2 pricing and suggest straightforward ways to reduce EC2 costs without impacting your workloads.
What are EC2 Instances?
Elastic Compute Cloud (EC2) instances are virtual servers that can be used to run applications on Amazon Web Services (AWS).
When creating instances, you can choose from 28 instance types, providing different levels of CPU, memory, and networking resources, depending on your budget and needs. Instance types fall into five main categories: General, Compute Optimized, Memory Optimized, Accelerated Computing, and Storage Optimized.
You create EC2 instances using an Amazon Machine Image (AMI). The AMI contains the operating system and other preconfigured settings. AWS includes a variety of pre-built AMI templates that can be obtained directly through AWS or on the AWS Marketplace. You can also create your own AMIs for custom configurations.
Amazon EC2 Instance Pricing Models
Amazon EC2 provides the following pricing models for compute instances:
Free tier—you can use 750 hours of t2.micro instances per month free for the first year after you create your Amazon account.
On-demand instances—on-demand instances are charged per hour or second used, with no long-term commitment. You can start or stop instances at any time and pay only for the time used.
Spot instances—instances offered a discount of up to 90% because they are part of Amazon's spare capacity. Spot instances may not always be available in the instance type and availability zone (AZ) you need. They also do not guarantee reliability—a spot instance can be terminated with 2 minutes’ notice.
Reserved instances—provide a discount of up to 75% in exchange for committing to using the instance for a term of 1 or 3 years. You have the option of paying some of the amount upfront, which grants a bigger discount.
Savings Plans—Amazon offers lower prices on EC2 usage if your organization commits to a level of spend on EC2 and Amazon Fargate resources over 1 or 3 years. Savings plans enable savings of up to 72%.
7 Ways to Save On EC2
Let’s cut to the chase: here are a few ways you can cut a significant percentage off your EC2 costs.
1) Identify and Stop Instances with Low Utilization
An easy way to save EC2 costs is to identify running EC2 instances that are idle or underutilized. You can then reduce your costs by stopping or reducing them. There are a few ways to do this:
Use the AWS Billing and Cost Management tool to identify under-used instances
Use AWS Instance Scheduler to stop instances automatically
Use AWS Operations Conductor to automatically right-size EC2 instances
2) Use Spot Instances and Prepare for Interruptions
When you use spot instances, you enjoy substantial discounts, but you also need to handle Spot Instance outages. The best approach is to design your application to be fault-tolerant. EC2 provides two types of signals you can use to prepare for a failover event:
Spot instance interruption notice—EC2 issues an alert two minutes before it stops a spot instance. If your workload is time flexible, you can configure spot instances to stop or hibernate when they are interrupted instead of terminating them. Amazon EC2 can automatically suspend or hibernate spot Instances and automatically resume them when capacity becomes available.
EC2 instance rebalancing recommendation—tells you when your Spot Instances are likely to be terminated. This signal gives you the opportunity to actively manage your Spot Instances before the 2-minute interruption notice. You can decide to rebalance your workloads to new or existing spot instances that don't have a high risk of disruption.
3) Use Spot Fleet
Spot Fleet is a feature provided by AWS that lets you configure capacity across multiple EC2 instance types and purchasing models—on-demand, reserved instances, and spot instances.
Spot Fleets lets you specify the target capacity and EC2 instance type depending on your use case and combine different pricing models as needed. For example, you can have several on-demand instances for core management components and additional spot instances for resources that can tolerate termination. In addition, you can specify the priority of swapping instance types and the Availability Zone they should run in.
You can use Spot Fleet Requests to define your allocation strategy. You can specify which instances should run first (on-demand, reserved, or spot) to meet capacity requirements.
Spot Fleets can help you save costs by utilizing spot instances while ensuring you have other instance types available for improved reliability.
4) Auto Scale EC2 Instances
The AWS Auto Scaling feature ensures you are running the correct number of Amazon EC2 instances to handle a specific application’s load. Auto Scaling dynamically adjusts compute performance based on a predetermined schedule or actual load metrics—increasing or decreasing the number of instances as needed.
Amazon provides a variety of scaling strategies you can use to adapt capacity to actual needs. By scaling down capacity dynamically, you can reduce wasted resources and save costs.
To maximize cost savings, configure Auto Scaling using the appropriate level of granularity. If you set Auto Scaling for workloads that are too large or contain too many compute instances, you may over-provision capacity.
5) Right Size EC2 Instances
Right-sizing means selecting an EC2 instance type that is an exact match for your application or workloads to prevent under-utilized resources.
To understand the type of instance needed by a particular application, determine the level of CPU and memory resources used by that application. Once you have this information, you can configure the instance type and number of instances that are best suited for your workload.
Proper sizing also helps you make the most of your reserved instance purchases. After determining the ideal configuration for your instance, you can further reduce costs by committing to a term of 1 or 3 years and purchasing reserved instances.
The downside of using right-sizing for cost management is that it is suited for workloads with relatively stable traffic. If you are dealing with volatile workloads, it will be tricky to determine the right size, and reserved instances may often be underutilized.
6) Identify and Delete Orphaned Snapshots
By default, terminating an EC2 instance also deletes all attached EBS volumes. However, it's easy to forget that snapshots you previously saved are still on S3 and continue to incur monthly charges.
These costs may be higher than you think. Most backups are incremental, but the first snapshot captures the entire volume. Also, over a long retention period, incremental snapshots may require even more storage space than the original full snapshot.
So, although S3 is cheaper than EBS volumes, you need a strategy for deleting EBS volume snapshots when you delete an EBS volume. Over time this can generate substantial savings in storage costs.
7) Leverage GPU Instances
When running machine learning or deep learning workloads, it is recommended to use Amazon’s new GPU instances, such as the P3 or G3 series. Although GPU instances are more expensive per hour, training machine learning models on them can be faster by an order of magnitude. This can generate overall cost savings.
Another tip is to use multi-GPU capabilities in machine learning frameworks to distribute loads across multiple GPU instances. This can lead to better utilization of GPU resources and additional cost savings.
Conclusion
I provided seven ways you can dramatically cut EC2 costs. Some of them require work but will be well worth it in the long run:
Identify EC2 instances with utilization and remove or merge them
Use spot instances to get discounts of up to 90%
Use spot fleet to combine spot instances with on-demand or reserved instances
Autoscale EC2 instances to ensure you scale down when necessary
Right size EC2 Instances to ensure you are not over-sending on expensive instant types
Identify and delete orphaned EBS snapshots
Use GPU instances to run machine learning workloads faster
I hope this will help you cut your costs on AWS and divert resources to more useful avenues.
About the Author
You May Also Like