Review the required ECS service task count

Check the desired task count and actual running state against the service’s operating needs.

Description

For an ECS replica service, desired_count = 0 requests that all tasks stop. This can be intentional for a planned shutdown or autoscaling. DAEMON services do not use this setting.

Potential impact

If capacity is short or deployment fails, the service can have no tasks to handle requests even with a positive desired count.

Remediation

For an always-on replica service, set desired_count to at least one and size it for the traffic. Check running and pending counts, deployment status and task health. Set an alarm for loss of availability.

Examples

To scale an existing service, keep its name, cluster, task definition and launch configuration and change only desired_count. The second excerpt instead describes a Fargate service with a different name and cluster and requires awsvpc subnets.

Before

hcl
resource "aws_ecs_service" "example" {
  name          = "example"
  cluster       = aws_ecs_cluster.example.id
  desired_count = 0
}

After

hcl
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"
}

Requesting one task leaves no spare to handle traffic if it fails.

References