1 min
read
Since January 19, 2024, a new feature has been available on ECS: automated instance draining. This feature allows for the secure and scheduled shutdown of workloads (containers) deployed on EC2 instances.
As a reminder, AWS ECS offers two modes for executing container tasks: Fargate or EC2.
- Fargate enables the execution of containerized applications without managing an instance cluster.
- By deploying directly on EC2 instances, you gain more control over the infrastructure, but it involves managing all maintenance operations such as instance configuration, security updates etc..
EC2 Managed instances draining
This feature facilitates the gradual shutdown of workloads deployed on EC2 instances by safely stopping and rescheduling workloads on other instances.
This simplifies infrastructure maintenance operations, such as deploying a new AMI version. Automated draining covers various use cases:
- During scaling (scale-in, instance removal)
- For implementing instance maximum lifespan
- During stack updates in CloudFormation
- For spot instances:
- During interruptions
- During capacity rebalancing
To benefit from this new feature
- For new capacity providers: nothing needs to be done; it will be enabled by default.
- For existing capacity providers, it needs to be activated:
- Manually in the AWS console (flag)
- Using the command line
Or, like our clients who efficiently managed their infrastructure with Terraform:
- Update the AWS provider to the latest version
- Activate the feature in your aws_ecs_capacity_provider resource:
- Set the attribute managed_draining to "ENABLED"
Terraform registry: ecs capacity provider
Managed draining was a highly anticipated feature missing from this orchestrator. Previously, if smooth draining was desired, one had to implement a complex system based on event listening for scaling with Lambda functions to check certain states and trigger actions accordingly.
Source : Amazon ECS : managed instance draining