36

Haven't been able to find this in docs. Can I just pause an ECS service so it stopped creating new tasks? Or do I have to delete it to stop that behavior?

I just want to temporarily suspend it from creating new tasks on the cluster

red888
  • 27,709
  • 55
  • 204
  • 392
  • From what I recall, pausing continues to run background tasks and I had to dive deep into identifying, stopping/deleting the instances from spinning off other dependency services. – user2347763 Mar 20 '18 at 23:01

3 Answers3

46

It is enough to set the desired number of tasks for a service to 0. ECS will automatically remove all running tasks.

aws ecs update-service --desired-count 0 --cluster "ecs-my-ClusterName" --service "service-my-ServiceName-117U7OHVC5NJP"
wasserholz
  • 1,960
  • 2
  • 20
  • 26
16

You can accomplish a "pause" by adjusting your service configuration to match your current number of running tasks. For example, if you currently have 3 running tasks in your service, you'd configure the service as below:

.

This tells the service:

  • The number of tasks I want is [current-count]
  • I want you to maintain at least [current-count]
  • I don't want more than [current-count

These combined effectively halt your service from making any changes.

MrDuk
  • 16,578
  • 18
  • 74
  • 133
  • 1
    ah yes, this makes sense. And i could set to 0 tasks to "turn off" the service. feel dumb for no coming to this conclusion myself – red888 Mar 21 '18 at 19:29
  • 10
    Don't feel bad, AWS is notoriously ambiguous in much of their UI – MrDuk Mar 21 '18 at 19:31
13

The accepted answer is incorrect. If you set both "Minimum healthy percent" and "Maximum healthy percent" to 100, AWS will give you an error similar to following:

enter image description here

To stop service from creating new tasks, you have to update service by updating task definition and setting desired number of tasks to 0. After that you can use AWS CLI (fastest option) to stop existing running tasks , for example:

aws ecs list-services --cluster "ecs-my-ClusterName"
aws ecs list-tasks --cluster "ecs-my-ClusterName" --service "service-my-ServiceName-117U7OHVC5NJP"

After that you will get the list of the running tasks for the service, such as:

 {
    "taskArns": [
        "arn:aws:ecs:us-east-1:XXXXXXXXXXX:task/12e13d93-1e75-4088-a7ab-08546d69dc2c",
        "arn:aws:ecs:us-east-1:XXXXXXXXXXX:task/35ed484a-cc8f-4b5f-8400-71e40a185806"
    ]
}

Finally use below to stop each task:

aws ecs stop-task --cluster "ecs-my-ClusterName" --task 12e13d93-1e75-4088-a7ab-08546d69dc2c
aws ecs stop-task --cluster "ecs-my-ClusterName" --task 35ed484a-cc8f-4b5f-8400-71e40a185806

UPDATE: By setting the desired number of running tasks to 0, ECS will stop and drain all running tasks in that service. There is no need to stop them individually afterwards using CLI commands originally posted above.

azec-pdx
  • 4,790
  • 6
  • 56
  • 87
  • Thanks, looks like they updated what's allowed since I posted my original answer. – MrDuk May 14 '19 at 12:56
  • 4
    Update: setting desired number of running tasks to 0, will stop all running tasks in that service. No need to stop them individually afterwards. – wasserholz Jul 04 '19 at 06:48