If you are running few non production environments on AWS Elastic Beanstalk you were probably wondering how do you put its servers to sleep during the off work hours just to save few 💰💰💰?
There is a simple trick that AWS provide, but don’t promote it for a reason. As a result not many know about it. ;)
All you need to do is to define two time periods in your environment Configuration -> Scaling -> Time-based scaling section.
One period with cron based time settings to Stop your EC2 environment machines and the other one to Start them.
Here is cron definition to reduce number of EC2 machines to zero at 17:00 UTC every working week day — 0 17 * * 0,1,2,3,4
And a cron definition to increase number of EC2 machines to one at 05:00 UTC every working week day — 0 5 * * 0,1,2,3,4
What it actually does is terminates and recreates the machines as AWS doesn’t allow to suspend/pause EC2 machines.
If you can afford to run without Elastic Load Balancer it will save you even more as this trick won’t terminate the LB. 🤑