Gayan Hewa
PHANTOM DEV

PHANTOM DEV

AWS ECS Service with One Task

AWS ECS Service with One Task

Subscribe to my newsletter and never miss my upcoming articles

AWS ECS Service with One Task

29 Aug 2021 | 2 min read

If you are reading this, it's likely that you are trying to release some code into your AWS ECS Service with a single task but it just doesn't seem to complete. And you have got a butt load of the following error

service my-fancey-service was unable to stop or start tasks during a deployment because of the service deployment configuration. Update the minimumHealthyPercent or maximumPercent value and try again.

So what is going on here?

ECS is not very intelligent. Like most of the tools we use, it's meant to do stuff based on certain contractions we configure. I think it is an intentional design decision, but I could be wrong. Anyways, when a service is deployed in ECS there are a whole lot of constraints and rules we can configure for the service.

But, the one that causes this particular issue is as explained in the error minimumHealthyPrecent and maxiumPrecent values.

Unlike services that have more than one task, when a service is configured to deploy only a single task.

The service is only able to have a maximum of 1 task running at any given point in time.

When you release a new service, you essentially start the new task in the service and then promote the new task to be the primary task and the old ones get deleted eventually. When the max is at 100% and the service can only hold 1 task at any given point in time, the new release is unable to start the task and continues to timeout until the service status check considered that it had failed.

To overcome this, it's essential that we set the max percent to be at least 200% this will ensure that at a minimum the service can have at least 2 tasks running at any given point in time.

And just like that, you've solved your problem with ECS not releasing your service with a single task.

Now, if you are curious as to why doesn't happen when we have more than one task. It's simple really. If you have 2 tasks and Max percent set to 100% that would basically translate into at any given point in time this service can have a maximum of 2 running tasks. During a new release, the service will swap out one task at a time. First a stop one of the running tasks and then start a new task from the new release. And once it's stable stop the other task from the previous release and places a new task from the new release.

Feel free to reach out to me if you have any questions @phantom6thdev

#docker #containers #ecs #aws

← Maximum Sub-array Problem Serve static assets with an efficient cache policy in a few minutes →

 
Share this