2

I have an ECS Fargate service which uses CloudWatch alarms to scale-in/scale-out using service auto-scaling. The task containers have long processing times (upto 40 minutes) and I don't want a running container to get killed when a scale-in happens. Is there way to do that for an ECS task/service?

PS: I have looked at the stopTimeout property in a task-definition but its max value is only 120 seconds. I have also looked at scale-in protection for EC2 instances but haven't found any such solution for an ECS Fargate task.

Dhruv Pargai
  • 121
  • 5
  • What metric is triggering the auto-scaling? Usually when you have a specific long-running task like that, you wouldn't use ECS services (and auto-scaling) at all, you would use AWS Event Bridge to directly trigger the creation of new ECS tasks. – Mark B Jan 27 '22 at 13:43

1 Answers1

0

Support for ECS task scale-in protection was released on 2022-11-10: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-scale-in-protection.html

In summary, you can use the new ECS container agent endpoint from inside a task to mark it as protected:

PUT $ECS_AGENT_URI/task-protection/v1/state -d 
'{"ProtectionEnabled":true}'

Alternatively, you can use the UpdateTaskProtection API to achieve the same result from outside the task: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateTaskProtection.html

Justin Lewis
  • 1,261
  • 1
  • 15
  • 33