3 min read

Cut your AWS bill with scheduled scale-to-zero

Non-production environments do not need to run overnight. Schedule them to zero and back on a timer, and cut idle spend without touching production.

AWS cost optimizationAWSCost OptimizationECSDevOps

Most non-production environments run all day and all night while people use them for a few hours on weekdays. You pay for every idle minute. On one platform I cut recurring ECS spend materially by scaling non-production to zero overnight and on weekends. Nothing else changed. Here is the pattern and how to apply it.

Where the waste hides

Look at when your environments are actually used. A development or staging environment might see real traffic 40 hours a week. Left running, it bills for 168. That is more than 75% of its runtime spent doing nothing.

Production has to stay up. Everything else does not. Development, staging, QA, and demo environments can sleep when no one is working, and the savings compound across every environment you run.

Scale ECS Fargate to zero on a schedule

If you run containers on ECS Fargate, you pay per running task. Set the desired count to zero when the environment is idle and back up when the day starts.

  1. Add a scheduled action that sets the service desired count to zero in the evening.
  2. Add a second scheduled action that restores the count in the morning.
  3. Skip weekends entirely for environments no one touches on Saturday and Sunday.

Application Auto Scaling supports scheduled actions for exactly this. AWS documents scheduled scaling for ECS services, and you can drive the schedule with EventBridge Scheduler.

Do the same for other idle resources

Fargate is the easy win, but it is not the only one. Apply the same thinking across the environment.

  1. Stop non-production databases when the compute is off, since a database with nothing talking to it is pure cost.
  2. Turn off scheduled jobs and workers that only exist to serve a sleeping environment.
  3. Leave storage alone. The goal is idle compute, not your data.

Keep production untouched

The rule that makes this safe is simple. Only non-production scales to zero. Put the schedule behind a per-environment flag so production can never pick it up by accident. I parameterize this in Terraform, so each environment declares whether it is allowed to sleep, and production always answers no.

Measure what you saved

Confirm the win. Tag resources by environment and use Cost Explorer to compare the month before and after. You will see the non-production line drop while production stays flat. Check current rates on the AWS Fargate pricing page so you can estimate the saving before you build it.

The takeaway

Idle non-production is the easiest money you will ever save on AWS. Scale it to zero on a timer, keep production out of the schedule, and measure the drop. On one platform this cut recurring ECS Fargate spend without touching application code. For more serverless cost and performance wins, read taming Lambda cold starts.

Frequently asked questions

Is it safe to scale production to zero too?

No. Production should stay available. Restrict the schedule to non-production with a per-environment flag so production can never be scaled down by accident.

What if someone needs the environment after hours?

Give them a way to start it on demand, such as a small script or a manual scale-up action. The schedule handles the normal case, and people can override it when they need to.

How much can I actually save?

It depends on how long your environments sit idle. An environment used 40 hours a week but running 168 spends most of its life idle, so scaling it to zero overnight and on weekends can cut its compute cost by more than half.

Does this work outside ECS Fargate?

Yes. The idea is the same for any per-time cost. Stop idle databases, pause workers, and turn off scheduled jobs that only serve a sleeping environment.

Will cold starts slow the first request after scale-up?

There is a short warm-up while tasks start. Schedule the scale-up a little before people arrive, and the environment is ready when they need it.

Comments

    Leave a comment