- Newest
- Most votes
- Most comments
The issue you're experiencing is related to how ECS manages task placement and capacity during deployments. Even though you have configured your service for a rolling update with 100% minimum and 200% maximum running tasks, the auto scaling group isn't automatically scaling up during deployments because of several potential factors:
-
Resource Constraints: When you force a new deployment, ECS tries to place the new task, but if your EC2 instance doesn't have enough resources (CPU, memory, or ports) to run both the existing and new task simultaneously, the new task will remain in a pending state.
-
Port Conflicts: If your container is using host networking mode and binding to specific ports, the new task might not be able to start because the required port is already in use by the existing task.
-
Auto Scaling Trigger: Your auto scaling group is configured to scale based on a Custom CloudWatch metric at 100, but this metric might not be triggered during a deployment if it's not directly related to the pending task state.
To address this issue and achieve the behavior you want (spinning up a new instance for deployments), consider these solutions:
-
Adjust Capacity Provider Strategy: Ensure you have properly configured your capacity provider strategy to manage the scaling of your EC2 instances based on task demand. Please see How do I troubleshoot scaling issues with my Amazon ECS capacity provider?
-
Enable Managed Instance Draining: This allows ECS to gracefully remove tasks from an instance that's being scaled in, ensuring that new tasks can be placed on other instances.
-
Use awsvpc Network Mode: If possible, consider using the awsvpc network mode instead of host networking to avoid port conflicts during deployments.
-
Review Task Placement Strategy: The default strategy is to spread tasks across Availability Zones, but you might want to consider using a different strategy to optimize resource utilization.
-
Implement Service Auto Scaling: This can automatically adjust the desired count of tasks based on CloudWatch metrics, which can help ensure you have the right number of tasks running to handle your workload.
By implementing these changes, you should be able to create a more efficient deployment process that automatically scales out when needed for deployments and scales back in when the extra capacity is no longer required.
Sources
Running Update Service shows a pending task, but never shuts down the existing task so a new deployment runs | AWS re:Post
ECS Task Deployment Doesn't Reserve More Capacity | AWS re:Post
ECS (EC2 launch type) new deployment container fails to start with no clear error message | AWS re:Post
answered a year ago
Relevant content
asked 10 months ago
asked 4 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago

I updated the question with the metric definition. I don't know what this means "...metric might not be triggered during a deployment if it's not directly related to the pending task state." As far as I can see the CapacityProviderReservation is at 100% which I would say is directly related to pending task state.