Description
For an ECS replica service, desired_count = 0 requests zero tasks. This can interrupt a service that must continuously handle requests, but it can be intentional for a planned stop or scaling to zero. Desired and actual running counts differ, so also check the service’s running state.
DAEMON scheduling does not manage the task count through desired_count.
Potential impact
- A service cannot handle requests when its required tasks are not running.
- Capacity shortages or deployment failures can prolong an outage even with a positive desired count.
Remediation
Set an appropriate desired_count of at least 1 for replica services that must remain active. Check running and pending counts, capacity, deployment status, and health checks. Manage planned stops or autoscaling to zero according to operational intent, and configure availability alarms.
Examples
These excerpts compare desired counts. Use actual cluster and task-definition references and supply omitted settings, including the required task definition and networking.
Before
resource "aws_ecs_service" "example" {
name = "example"
cluster = aws_ecs_cluster.example.id
desired_count = 0
}
After
resource "aws_ecs_service" "example" {
name = "km_ecs_service"
cluster = aws_ecs_cluster.km_ecs_cluster.id
task_definition = aws_ecs_task_definition.km_ecs_task.arn
desired_count = 1
launch_type = "FARGATE"
}
The second excerpt requests one task. Verify that it actually runs and is healthy; a desired count of one does not itself provide high availability.