Enable AWS ECS managed draining

Dien Bui
2 min readJan 20, 2024
Source: https://www.weave.works/blog/microservices-amazon-ecs/

If you are software engineer with experience in using AWS ECS (Elastic Container Service), you definitely want to have a feature to drain EC2 from associated ASG and reduce downtime of the service during patching. For years, we have been using a custom AWS Lambda to perform this action, which can increase complexity of the infrastructure.

Luckily, on 19 Jan 2024 AWS released new feature called “Managed draining” of ECS (announcement link) and with this feature you can abort the custom AWS Lambda and enable this right from ECS capacity providers.

This post will show you how to enable it for any existing ECS cluster. For new one it will be turned on by default. As of published date of my post, AWS providers from Terraform and Pulumi have not published new version to support this.

Firstly, head to the Infrastructure tab of your ECS cluster, choose a provider and click “Update”

ECS capacity providers

In the new page, check this checkbox and click “Update”

Once done, wait for the “Update status” to show “Update completed”

Before performing any patching to see the effect, remember to disable/remove any hook and AWS Lambda used for draining you had to avoid conflict.

Finally, to test the new config, you can apply new Launch Template version for the associated ASG and see the status of the instances as well as the rolling deployment of the services inside cluster.

--

--

Dien Bui

Backend, data and cloud computing enthusiast | Power of open-source and sharing believer | Platform Engineer @ NAB | Co-founder of Project Cocoon