AWS Step-by-Step

Ten Easy Ways to Reduce Your EC2 Costs, Part 1

When it comes to running EC2 instances, cost is almost always top of mind. It's a given that there will be a cost associated with each virtual machine instance that you run in the Amazon cloud, but that doesn't mean that you should overpay. There are some easy things that you can do to bring down your EC2 costs without adversely impacting your workloads in the process.

1. Right Size Your Instances
Instance right sizing is one of the easiest and most effective ways to drive down your EC2 costs.

When you create an instance, you will need to pick an instance type, which determines the hardware that will be allocated to the instance. Amazon offers dozens of different instance types, each with their own unique pricing.

If an instance is performing well, but is costing more than you feel like it should, then take a look at the CloudWatch metrics associated with the instance. If your instance isn't leveraging most of its CPU, memory, and storage resources, then you may be able to downgrade to a smaller instance type. This will immediately reduce the cost of running the instance.

2. Use Savings Plans or Reserved Instances
Another way to reduce your EC2 cost is to take advantage of savings plans or reserved instances. Savings plans are a pricing model in which Amazon agrees to host your instance at a reduced hourly rate in exchange for you committing to run the instance for a specific length of time. The commitment period is usually either one year or three years. While such a commitment does lock you into spending a certain amount of money over the time period that you have agreed to, using a savings plan can bring down your costs by as much as 66%.

Reserved instances are somewhat similar to using a savings plan, but you can opt to reserve an instance for as little as one month. Additionally, you can choose to pay for the instance up front if you want. Even though reserved instances can save you money, Amazon generally recommends that customers use savings plans instead.

3. Use Spot Instances
Spot instances are not suitable for every workload, but if you are able to use them, they can save you up to 90% as compared with the cost of running an on demand instance. The reason why spot instances are so cheap is because spot instances represent unused capacity within the Amazon cloud. Rather than just letting this unused capacity go to waste, Amazon makes it available to customers at a deeply discounted price.

Spot instances are not suitable for every workload, but if you are able to use them, they can save you up to 90% as compared with the cost of running an on demand instance. The reason why spot instances are so cheap is because spot instances represent unused capacity within the Amazon cloud. Rather than just letting this unused capacity go to waste, Amazon makes it available to customers at a deeply discounted price.

As previously mentioned however, spot instances are not suitable for every workload. The reason for this is that, as noted, spot instances run using excess capacity. However, if this excess capacity is suddenly needed by a higher priority workload then the spot instance is immediately shut down.

That being the case, spot instances should only be used for running workloads that can tolerate interruption. For example, you might use a spot instance for dev / test workloads or for stateless workloads such as application front ends.

4. Auto Scale Your Instances
Another way that you can help to control the costs associated with running EC2 instances is to take advantage of auto scaling. Suppose for a moment that you have a large and resource intensive workload that you want to run on EC2. Rather than creating a single instance that is based on a gigantic instance type, you could instead create a lot of smaller instances that collectively handle your workload's demands.

Assuming that these smaller instances are all configured similarly with regard to the instance type, AMI, and network configuration, you could group the instances together within an auto scaling group. From there, you could create scaling policies that tell AWS when to add or remove instances. Scaling could occur in response to resource utilization. Scaling can also be based on a schedule, and it is even possible to perform predictive scaling.

5. Schedule Instances to Automatically Shut Down
Not every instance needs to run twenty four hours a day. A Dev / test instance for example, might only need to run late at night or on the weekends.

There are a few different ways to automatically stop instances. You could for example, create a Lambda function that is designed to shut down instances You could call this function using an EventBridge rule. Other options include using an AWS Systems Manager Runbook to automatically shut down certain instances, or to write a PowerShell script (you can use the Stop-EC2Instance cmdlet).

It is important to note that turning off an instance will not eliminate all of the costs associated with that instance. An instance will incur some costs simply because it exists. However, an instance that is powered off consumes far fewer resources than a running instance, hence the costs will be substantially lower.

In Part 2 of this series, I will share with you five more ways that you can reduce your EC2 costs.

About the Author

Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.

Featured

Subscribe on YouTube