1. Cost Optimization Strategies
Cost optimization strategies, if used correctly, present some fascinating savings opportunities. Let's understand what those are.
2. Cost optimization framework
There are five steps to AWS cost optimization.
The first is to use the right-sized resources. If your task requires a 2-CPU server, don't use an 8-CPU server.
Next, with elastic capacity, you can allocate resources only when there is a business need and switch them off at other times.
You can leverage different pricing models to find additional savings.
Alternative services such as Lambda, can be a great lower-cost alternative to EC2 servers for short-duration tasks.
Finally, cleaning out unused storage will result in less storage costs. Let's discuss these with an example use case.
3. Optimization example
Let's look at an example. A company uses 12 EC2 servers, a database service, and S3 storage and pays $15,000/month.
Four servers each have been allocated based on peak usage for the three different tasks: service web requests, process uploaded images, and data analytics.
4. Optimize size and capacity
All servers have been found to be adequately-sized for CPU & memory. Serving web traffic requires at least one server to be running 24/7. A few traffic surges require a maximum capacity of four total servers. However, total usage of additional servers over a 24 period is only 24 server-hours across 3 surge servers. In other words, we can save 48 server hours (or 50%) of the usage with elastic server capacity. This is possible using something called 'Auto Scaling group'.
5. Leverage pricing model
WE can find savings for the the four analytics/ETL servers. These servers are running 24/7 but can be optimized. Spot instances offer an average savings of 66% over on-demand rate.
This company's analytics batch workload can tolerate interruptions. Moving from 24/7 on-demand instances to four spot instances will reduce the costs from $4,000/month to $222/month or a savings of approximately 94%.
6. Explore alternatives
AWS Lambda, an alternative to EC2, is a serverless compute service for running code without having to provision servers.
Lambda is ideal for short-term tasks. EC2, in contrast, is intended for long-term, steady-state operations. Image upload and processing task is perfect for Lambda.
Lambda offers a generous one million free requests per month. Replacing 4 EC2 servers with Lambda will save $4,000/month in server costs.
7. Optimize storage
Over time, increasing storage increases costs. Rather than cleaning out files individually, it is easier to create rules which define how the files will purge. These rules are called lifecycle policies.
Implementing auto-purge will save $500/month or **50%** of the storage costs.
8. Savings summary
Starting from $15,000/month, we've reduced our AWS bill by a whopping 68.52% to $4,722/month. The biggest savings were found optimizing EC2 workloads and replacing EC2 with Lambda.
While these savings are impressive, the specific savings you may achieve will depend on your workload characteristics and business requirements.
9. Let's practice!
Let's work on a few cost optimization exercises!