Hi guys.
Today, I’d like to share with you a technique I’ve typically used in my work. This technique is called Kaizen.
So, what is Kaizen, and why should you care? Great question. Kaizen is a continuous improvement method that is used in manufacturing. For some, you might be familiar with similar methods like Lean in Project Management or the Toyota Production System (TPS). Kaizen was first introduced in the 1960’s when engineer Taiichi Ohno, who created TPS. It was designed to achieve objectives like improving quality, increasing profitability, and reducing costs.
Normally, each of my PRs consists of a dedicated task and a small improvement. This could be anything, such as adding logging, encapsulating code and covering it with unit tests or reduce unnecessary http requests. Some might refer to this as following the "Boy Scout Rule" and it will be absolutely right. In my humble opinion it is just adjacent topic.
So, I’d like to share a story about how I used this technique to reduce our AWS monthly bill.
Requirements
The application I’ve been working on includes some third-party integrations, and to test the entire workflow, I came up with the idea of spinning up an EC2 instance with primitive logic to simulate those integrations. Everything worked perfectly until I noticed that, most of the time, the instance was idle. So, I did a quick calculation and realized that I could save $1.46 per environment per month by optimizing this setup. Then I considered an effort to implement it and got a green light from a PM to implement it.
Calculations
Before
1 instances x 0.006 USD On Demand hourly cost x 730 hours in a month = 4.380000 USD
After
1 instances x 0.006 USD On Demand hourly cost x 486.66666666666663 hours in a month = 2.920000 USD
Solution
The solution is straightforward and consists of three steps:
- Create a New AWS Role: Set up a new AWS role with permissions to start and stop EC2 instances.
- Set Up CloudWatch Rules: Create two CloudWatch rules—one to start the EC2 instance and another to stop it at predefined times.
- Implement a Lambda Function: Use AWS SDK within a Lambda function to send start and stop commands to the EC2 instance.
That’s pretty much it! The next step is to get rid of the EC2 instance entirely and use only AWS Lambda, with input and output stored in S3. Considering AWS Lambda’s generous free tier, I anticipate the cost will be $0.
It’s the little details that are vital. Little things make big things happen. ~ John Wooden
NOTE: The source code you can find here.
Top comments (0)