Best Practices Scaling Services in ECS on Business Hours

Hello everyone,

I want to scale down my services outside of business hours. I use Terraform to maintain my infrastructure. Should I redeploy my infrastructure with a different set of Terraform variables based on if we are inside or outside of business hours from a Lambda function with Terraform apply or should I just change the desired count through the AWS API with the Lambda function and use a lifecycle ignore changes on the desired count in the Terraform configuration? Jenkins is not an option for me.

Crone Job Scheduler that will trigger the lambda function

Yes but how should the lambda make the changes happening (of the 2 options I presented)

Since you’re using terraform, you might want to consider creating a scheduled action to scale in/out on a schedule. No lambda function needed then.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_scheduled_action Has a section on ECS

Set up an autoscalingng group?

This is the right answer in general.

The autoscaling group will give more control, it will be simpler to manage and will pick the right value for you resulting cheaper.

To simplify, you come up with a metric that represents how much load is currently in the system and then ask AWS to spin up or down instances to maintain that metric at a specific value (eg. 80%)

If you can’t scale based on usage, ECS also supports scheduled scaling. Here’s an article to set it up:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-autoscaling-schedulescaling.html

There’s a number of ways to have ECS automatically scale for you. It’s pretty standard to scale based on CPU usage, but you can use other triggers if that doesn’t work for your use-case.

This article discuses different approaches:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html

Set a schedule scaling policy using terraform. Check if the aws provider has the resource for it that should be straight forward.

Literally this:

https://stackoverflow.com/questions/61081382/scheduled-ecs-scaling-using-terraform

Event -Bridge trigger → Use Update Service action → Set desired count and schedule

just use auto scaling group and schedule the hours where it will be reduced.