Search code examples
amazon-ecsaws-fargateaws-application-load-balancer

Configure ECS to scale to zero when not in use


I'm running Superset in AWS ECS using Fargate. This instance of Superset is for internal use only. I want to be able to configure ECS to scale to zero tasks when not in use. I am aware that it will take time (Possibly minutes) to come back up, the end-users of this application are content with waiting a few minutes.

Situation:

  • AWS ECS deployed using Fargate
  • Autoscaling set to a max of 2 and a min of 0
  • Want to scale to 0 when not in use (after, say, an hour)

Solution

  • Scaling ECS down to zero when not in use is not possible. ECS is designed to run continuously, unlike Lambda functions that can be turned on and off as requests arrive.


    However, if your internal users only access the application during known hours (say business hours), then you can use scheduled scaling to scale to zero during specific hours.

    You can use put-scheduled-action for that.

    aws application-autoscaling put-scheduled-action --service-namespace ecs \
        --schedule "cron(15 12 * * ? *)" \ 
        ...
    

    This AWS Blog post explains it in more detail: https://aws.amazon.com/blogs/containers/optimizing-amazon-elastic-container-service-for-cost-using-scheduled-scaling/