I am running java process inside ecs fargate containers and have set-up auto scaling to scale-out when memory utilization is above 60% and scale-in accordingly. This setup is working fine but i am not able to figure out the criteria based upon which ecs determines which tasks it should shutdown as part of the scale-in events i.e how does it distinguishes between different tasks and picks one to shutdown ? Does it check if there any active requests on the tasks or not and then if there are multiple such tasks then picks randomly ?
-
1There is a concept of connection draining in load balancer. You can explore that. – Ankush Jain May 17 '22 at 04:26
3 Answers
There is a years long open issue about that on github:
From the issue and its comments you can infer the following:
Does it check if there any active requests on the tasks
No.
if there are multiple such tasks then picks randomly ?
Its random.

- 215,873
- 14
- 235
- 294
There is actually an update of this, now you can make your running task to be protected. Check this one for more details
https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-service-auto-scaling/

- 13
- 2
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Dragonthoughts Nov 25 '22 at 11:13
AWS announced a new feature in ECS called ECS scale-in protection in Nov 2022. This features determines that during the scale-out and scale-in it protects the tasks which are in process will be protected by ECS itself by evaluating this attribute ProtectionEnabled == true
and then ECS will not terminate that task.
Refer below blog post by AWS. They have explained it clearly with use cases. https://aws.amazon.com/blogs/containers/announcing-amazon-ecs-task-scale-in-protection/