AWS Principles: Optimize for cost

This AWS design principle is based on the financial reality of using cloud services. The magic of AWS is that you can use as much or as little resource as you want and only pay for what you use. The tragedy of AWS is that every month you get charged for (more or less) every piece of resource that you use. Optimizing for cost is not about minimizing the amount you spend. Closing your AWS account will reduce the bill, but at what impact on the business? The objective is to get as much business value as possible and only pay for things that deliver business value.

Understand the cost basis

Most AWS services have multiple dimensions to their cost; for example, we think of S3 as a couple of cents per month per gigabyte stored. The surprise cost can be data transfers out of your S3 bucket, either to the Internet or another AWS region, which can be around ten cents per gigabyte. S3 also has costs for API requests as well as data management such as S3 Intelligent Tiering. Depending on your use case, the storage cost may not be the most significant element. On the S3 bucket that holds the vBrownBag podcast videos for the iTunes feed, outbound data transfer by subscribers costs five times as much as storage. Another example is EC2; the cost per hour is top of mind, but remember that EC2 instances use EBS storage, and that has a charge per GB per month whether the instance is powered on or off.

Right Size

With EC2 instances, you pay per hour for a fixed amount of CPU, RAM, network bandwidth, and maybe a few other resources. If you only use 25% of any of these resources, you are still charged for 100%. It may be better to use a smaller EC2 instance size if all resources are lightly loaded or change to a different family if you need a larger proportion of one resource. AWS also releases newer versions of EC2 families, e.g., M6 replaces M5 (just watch out for the move to Graviton CPUs), and usually, the more recent instances deliver more performance for less money. You are being charged for all the resources; make sure they are all delivering value. Keep in mind that the RDS service uses managed EC2 instances; you can still right-size the instances.

Turn it off

The joy of AWS is that you can hand back resources that are no longer delivering value and stop paying for the resource. If you have EC2 instances that aren’t doing work right now, power them down and stop paying. If you simply power off instances at the end of work hours and power them on again before the start of the next workday, you can reduce the running hours of those instances by 60%. If there are instances that are not used every day, maybe don’t power them back on every day.

Enable Scalability

Not everything can be powered off and on, but many applications can scale-out and back in based on demand. Using smaller EC2 instances in an autoscaling group allows more granular scaling and less unused but still billed resources. Autoscaling doesn’t just apply to EC2. DynamoDB tables can be configured to autoscale performance by changing the RCU/WCU values automatically, and containers scale in and out when you use ECS or EKS. Scaling aims to have and pay for only the resources you need right now, paying only for value.

Buy smartly

The simplest way to buy resources from AWS is also the most expensive; if you make commitments to AWS, you can get considerable discounts. Either Reserved Instances or the more modern approach of Compute Savings Plans allow you to commit to AWS for one or more years and receive around 60% discount for that commitment. You still can also use on-demand instances, so you still get the flexibility to respond to increases in business. For the most significant savings, combine your multiple AWS accounts using AWS organizations and get the volume-based discounts across the consolidated bill for the organization. You can also make savings by being less committed, allowing AWS more flexibility by using EC2 spot instances. Spot instances can be a 90% discount off on-demand, but AWS might terminate your Spot instances because another customer wants to pay a lot more for them.

Use Managed Services

This was a bit of a surprise to me. Using an AWS-managed service is usually more cost-effective than building the service yourself. Normally, I expect to pay more for a more managed and abstracted service, but these services are generally more cost-effective for the same business outcome on AWS. The extreme example is AWS Lambda, event-driven computing, which puts a massive amount of the infrastructure work on AWS’s shoulders and lets customers focus on application code. For tasks that Lambda can (and should) perform, it is more cost-effective than running your code in EC2 instances that you manage.

Your AWS bill arrives every month; make sure that the money you spend is giving you as much business value as possible.

© 2021, Alastair. All rights reserved.

About Alastair

I am a professional geek, working in IT Infrastructure. Mostly I help to communicate and educate around the use of current technology and the direction of future technologies.
This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *