How We Reduced AWS Bill from $1,800 to $800 Monthly
Introduction
When working with AWS, cloud costs can quickly spiral out of control if resources aren't optimized properly. Recently, I had the opportunity to work on a legacy Ruby on Rails (RoR) application that was incurring high AWS costs due to inefficient infrastructure. Through strategic optimization, we managed to bring down the AWS bill from $1,800 to just $750–800, a reduction of over 55%. Here’s how we did it.
The Problem: High Costs & Inefficiencies
This legacy RoR application was running on AWS EC2 instances in a way that was far from optimal. Here were the key issues:
- No containerization – The application was running directly on EC2 instances without Docker, leading to deployment inconsistencies and inefficiencies.
- No ECS or Terraform setup – The infrastructure lacked automation, making scaling and provisioning manual and error-prone.
- Over-provisioned resources – Instances were oversized, leading to wasted computing power.
- Database inefficiencies – Expensive queries were slowing down the system and increasing costs.
- On-demand pricing – All instances were running on costly on-demand pricing without any Reserved Instances or Savings Plans.
The result? An AWS bill of $1,800 per month.
The Solution: A Complete Infrastructure Overhaul
To tackle these inefficiencies, we focused on a few key areas.
1. Containerizing the Application with Docker
The first step was Dockerizing the RoR application and introducing Nginx as a reverse proxy. This brought several benefits:
- Standardized environment across development, staging, and production.
- Easier deployment and scaling with containerized services.
- Improved resource utilization.
2. Migrating to AWS ECS with Terraform
Instead of running EC2 instances manually, we moved the workload to ECS (Elastic Container Service).
- Auto-scaling enabled – Containers now scaled based on demand, ensuring optimal resource usage.
- IaC with Terraform – Infrastructure as Code (IaC) ensured reproducibility and easy management.
- Eliminated unnecessary EC2 instances – Running services in containers meant better density and cost savings.
3. Right-Sizing Instances
We analyzed the actual workload requirements and resized the instances accordingly. This alone led to a significant reduction in compute costs, ensuring we only paid for what was necessary.
4. Database Optimization
The database was another major cost driver. We optimized queries by:
- Implementing stored procedures to reduce repeated expensive queries.
- Adding proper indexing to speed up searches and reduce CPU load.
- Optimizing connections and timeouts to prevent unnecessary database resource usage.
5. Purchasing Reserved Instances
Instead of relying on costly on-demand pricing, we purchased Reserved Instances for consistent workloads. This led to major cost savings as AWS provides significant discounts for reserved capacity.
The Result: A 55% Cost Reduction
After all the optimizations, the AWS bill dropped from $1,800 to just $750–800 per month. This not only reduced cloud costs but also made the infrastructure more scalable, maintainable, and efficient.
Key Takeaways
If you're dealing with high AWS costs, here are some key takeaways from this project:
- Containerize your application – It improves efficiency and makes scaling easier.
- Use ECS or Kubernetes – Moving to a container orchestration platform reduces management overhead.
- Right-size your resources – Avoid over-provisioning and pay for what you actually use.
- Optimize your database – Poor queries can drive up costs unnecessarily.
- Leverage Reserved Instances – Save big by committing to predictable workloads.
Conclusion
Cloud cost optimization is an ongoing process, but small, strategic changes can lead to massive savings. If you're running a legacy application on AWS and struggling with high costs, consider implementing these optimizations. Not only will you save money, but you’ll also improve performance, scalability, and maintainability.