Advanced AWS Cost Optimization Techniques

The quickest way to double your money is to fold it in half and put it in your back pocket.
- Will Rogers
We all might have gone through one day in our career to have a tradeoff on a wonderful idea with the cost factor! And I can pretty confidently say that cost will be always a key factor for any decision-making situation. Thus, here today we are going to touch on learning few cost optimization techniques for applications running in an AWS ecosystem.
Scope
In order to narrow down the scope of the document, let's pick out 10 commonly used AWS services for running a complete WEB application stack in the AWS infrastructure. Below are the few services we are planning to discuss today.
- Elastic Compute Cloud (EC2)
- Elastic Block Storage (EBS)
- Elastic Container Service (ECS)
- Lambda
- Simple Storage Service (S3)
- Relational Database Service (RDS)
- DynamoDB
- ElasticSearch Service
- Route53
- Cloudfront
Elastic Compute Cloud (EC2)
Web service that provides secure, resizable compute capacity in the cloud to run your application. Below are the key things to note to reduce the cost with EC2 instances.
- Purchase the right instance based on your application demands, especially with the vCPU’s and Memory. Monthly analyses on the usage of the instances will help you to right-size your instances to the optimum with the help of Cloudwatch.
- Prefer Spot instance types for non-production environments.
- Delete unused Elastic Load balancers.
- Use AWS instance schedulers to make your non-production instances run only on business hours (You can also use traffic request to warm the instances in non-business hours)
- Terminate unused instances and obsolete snapshots to reduce the storage cost.
- Start using Savings Plans to have a flexible pricing model that helps you save up to 72 percent on Amazon EC2 instances.
- Have strong retention policies for clearing the snapshot backups.
- Upgrade previous generation instance types to the latest.
Elastic Block Storage (EBS)
EBS is an easy to use, high-performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) for both throughput and transaction-intensive workloads at any scale. Below are a few methods to reduce the cost of EBS service.
- Reduce oversized EBS volumes.
- Delete unattached volumes.
- Choose Magnetic over SSD whenever is possible (especially non-production environments).
- Make sure you terminate the EC2 instances rather than stopping the instance as the EBS will be still serving cost for a stopped instance.
- Back up or have retention policies for EBS volumes. Make sure your backups also run incrementally and are deleted periodically.
Elastic Container Service (ECS)
Amazon Elastic Container Service is a fully managed container orchestration service. ECS allows your applications the flexibility to use a mix of Amazon EC2 and AWS Fargate with Spot and On-Demand pricing options. Below are the key things to note to reduce the cost with ECS cluster
- Use Compute Savings Plans which automatically apply to EC2 instance usage regardless of instance family in the ECS.
- Use Fargate and only pay for what your task uses, no more paying for EC2 capacity that goes unused.
- Use Fargate spot instances for the non-production workload.
- Use schedulers to make your non-production tasks run only on business hours.
Lambda
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume. Below are the few points to consider to optimize the cost incurred.
- For high traffic lambda functions, use provisioned concurrency to reduce cost (Lambda Power Tuning)
- Monthly analyzes on the usage of the lambda functions will help you to optimize the memory configurations
- Less frequently changed APIs and on high traffic requests situations, using API Gateway and caching layer will reduce the cost of invocation on the Lambda functions.
- Usage of Compute Savings Plans applies to the compute time consumed by your lambda functions, with savings of up to 17%.
Simple Storage Service (S3)
An object storage service that offers industry-leading scalability, data availability, security, and performance. Below are some suggestions to reduce the cost around the S3 service.
- Use S3 Intelligent-tiering for moving between frequent and infrequent access tiers automatically.
- Placing an S3 endpoint in your VPC gives any traffic to S3 its internal route and AWS won’t charge you like public traffic.
- Setup lifecycle policies to define the retention period for the objects especially for non-production environments.
- Use Glacier for archiving objects and use archive data backups long-term on Glacier Deep Archive.
- Regular clean up of obsolete objects and buckets.
Relational Database Service (RDS)
RDS makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching, and backups. Below are a few techniques to control the cost around RDS service.
- Use Aurora serverless for non-production environments.
- Single AZ deployments should be fine for non-production environments.
- Make us of General Purpose (SSD) storage if your database doesn’t have a constant I/O heavy workload over the entire usage period.
- Select the right instance for your database based on your application need.
- Go for Reserved Instance pricing models for the production environment if you can forecast the application growth.
- RDS Autoscaling will help you to solve the issue with over-provisioning resources.
DynamoDB
DynamoDB is a key-value and document database that delivers single-digit millisecond performance at any scale. It’s a fully managed, multi-region, multi-master, durable database with built-in security, backup and restores, and in-memory caching for internet-scale applications. Below are a few cost-cutting suggestions.
- Provisioned mode with autoscaling enabled will be cost-effective.
- Limit the record sizes, as request size matters up to a limit.
- Never use DynamoDB to store images, a link towards S3 would be optimal.
- For non-production environments, avoid strongly consistent reads and transactions.
- For fetching data, prefer queries over scans.
- For POC works, leverage DynamoDB free tier instances.
ElasticSearch Service
A fully managed service that makes it easy for you to deploy, secure, and run Elasticsearch cost-effectively at scale. Below are a few suggestions to reduce operational costs.
- Go with minimum configuration for non-production environments. No dedicated master instances and using one replica for your primaries could be an option.
- Reserved instances could be an cost-effective option for ES in a long run.
- Usage of UltraWarm can provide a cost-effective way to store large amounts of read-only data on Amazon Elasticsearch Service.
Route53
Amazon Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. Below are the few points to consider to optimize the cost incurred.
- For large organizations, consolidating your resolver endpoints from multiple AWS accounts could save you a lot.
- Increase TTL for records to reduce queries.
Cloudfront
CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. Below are some takeaways to reduce the cost incurred with CF.
- Use Cloud Front Private Contract & Volume Pricing for long term usages
- Save the data transfer cost by having a good caching strategy in Cloudfront.
- Enabling caching will reduce the computation cost of your underlying computing resources as well as improve the performance of your application.
- Check the cache hits ratio to adjust your configuration and TTL accordingly.
- Use Origin Access Identity in S3 to avoid loading assets directly from S3 and not bypass of CloudFront cache.
Having said that applying AWS cost optimization best practices is an ongoing process. I would personally advise monitoring your AWS cloud in a monthly fashion to identify when assets are being under-utilized (or not utilized at all) and when opportunities exist to reduce costs by terminating the zombie assets.
Wishing you all the very best and success in your cost optimization journey!