Learning center

ECS tasks stuck in PROVISIONING with a capacity provider

Read the task's lastStatus, the capacity provider's managedScaling, and the Auto Scaling group's size, activities and instances, in that order. Each step rules out one cause: a group already at MaxSize, a capacity provider that cannot scale the group, launches that fail, or instances that launch but never register with the cluster.

The signature#

A service uses an Auto Scaling group capacity provider. During a deployment or scale-out, its new tasks have lastStatus PROVISIONING and stay there. No stopped task explains it, because nothing has failed yet.

PROVISIONING means ECS has more steps to perform before the task launches. With an Auto Scaling group capacity provider, a task waits in this state for capacity: if the group cannot scale out to accommodate the tasks, they do not move beyond PROVISIONING. Task lifecycle · Auto Scaling group capacity providers

With managed scaling on, ECS publishes CapacityProviderReservation in the AWS/ECS/ManagedScaling namespace and drives a target tracking policy on the group with targetCapacity as its target. A value above 100 means tasks are waiting for instances. A short wait during scale-out is normal; a wait that outlasts instance launch and agent registration is the signature this guide covers. Cluster auto scaling

The nearby causes#

  • The group is at its maximum. ECS cluster auto scaling does not change the group's minimum or maximum size, so once DesiredCapacity equals MaxSize, nothing adds instances.
  • The capacity provider cannot scale the group. Managed scaling is DISABLED, the service has no capacity provider strategy, the ECS-managed scaling policy was changed or the AmazonECSManaged tag was removed, or the tasks are larger than the smallest instance type in the group.
  • Instances fail to launch. The group raised its desired capacity, but its scaling activities fail.
  • Instances launch but do not register. EC2 instances are InService in the group, but they never appear as ACTIVE container instances with a connected agent in this cluster.

Cluster auto scaling considerations · Managed scaling behavior

Read the task and the capacity provider#

Use a read-only profile and replace the uppercase placeholders.

aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN_1 TASK_ARN_2 \
  --query 'tasks[].{task:taskArn,definition:taskDefinitionArn,status:lastStatus,desired:desiredStatus,provider:capacityProviderName,created:createdAt,host:containerInstanceArn,cpu:cpu,memory:memory}' \
  --output table --no-cli-pager

aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{launch:launchType,strategy:capacityProviderStrategy,deployments:deployments[].{definition:taskDefinition,strategy:capacityProviderStrategy,running:runningCount,pending:pendingCount}}' \
  --output json --no-cli-pager

aws ecs describe-capacity-providers \
  --profile PROFILE --region REGION --capacity-providers CAPACITY_PROVIDER \
  --query 'capacityProviders[].{name:name,status:status,update:updateStatus,reason:updateStatusReason,asg:autoScalingGroupProvider.autoScalingGroupArn,scaling:autoScalingGroupProvider.managedScaling}' \
  --output json --no-cli-pager

A task with no capacity provider strategy is ignored by capacity providers and causes no scale-out; a service that sets launchType cannot set a strategy. A capacity provider can be used only when its status is ACTIVE. In scaling, check status, targetCapacity (above 0 and at most 100; the default 100 keeps no spare instances), minimumScalingStepSize, maximumScalingStepSize and instanceWarmupPeriod (300 seconds by default). ManagedScaling · CapacityProvider

Compare the task's cpu and memory with the smallest instance type in the group. A task group whose requirements exceed the smallest instance type cannot run with this capacity provider, the provider does not scale the group for it, and the task stays waiting. Managed scaling behavior

Read the Auto Scaling group#

aws autoscaling describe-auto-scaling-groups \
  --profile PROFILE --region REGION --auto-scaling-group-names ASG_NAME \
  --query 'AutoScalingGroups[0].{min:MinSize,max:MaxSize,desired:DesiredCapacity,suspended:SuspendedProcesses[].ProcessName,instances:Instances[].{id:InstanceId,type:InstanceType,state:LifecycleState,health:HealthStatus}}' \
  --output json --no-cli-pager

aws autoscaling describe-scaling-activities \
  --profile PROFILE --region REGION --auto-scaling-group-name ASG_NAME --max-records 10 \
  --query 'Activities[].{start:StartTime,status:StatusCode,message:StatusMessage,description:Description,cause:Cause}' \
  --output json --no-cli-pager

Activities are ordered by start time, with those in progress first. When a launch fails, the activity's StatusCode is Failed or Cancelled and its StatusMessage gives the cause. A suspended Launch process stops the group from adding instances, and a suspended AlarmNotification stops the alarms behind managed scaling from changing its desired capacity. Auto Scaling can also suspend processes itself, most often for a group that has tried and failed to launch instances for over 24 hours. Verify a scaling activity · Suspended processes · Activity fields · AutoScalingGroup fields

Then match the group's InService instance IDs with the cluster's container instances:

aws ecs list-container-instances \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --query 'containerInstanceArns' --output json --no-cli-pager

aws ecs describe-container-instances \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --container-instances CONTAINER_INSTANCE_ARN_1 CONTAINER_INSTANCE_ARN_2 \
  --query 'containerInstances[].{ec2:ec2InstanceId,status:status,reason:statusReason,agent:agentConnected,provider:capacityProviderName,registered:registeredAt}' \
  --output table --no-cli-pager

What each result means#

What you readCauseChange
desired equals max; every instance registered and fullThe group is at its maximumRaise MaxSize, or reduce what the deployment needs at once
scaling.status is DISABLED, or the service has a launchType instead of a strategyNothing scales the group for these tasksTurn on managed scaling, or set a capacity provider strategy on the service
Task cpu or memory exceeds the smallest instance typeTasks excluded from scale-outUse a separate group and capacity provider sized for these tasks
desired rose; activities Failed or Cancelled, or Launch suspendedLaunches fail or are blockedFix the cause the StatusMessage names, or resume the process
Instances InService, missing from the cluster or registered without providerInstances launch but do not registerCheck the instance's cluster setting, role and network path

An instance that registers without a capacityProviderName is not counted as this provider's capacity. AWS warns that instances already running in an existing group before it became a capacity provider might not be registered with the provider. Auto Scaling group capacity providers

For an instance missing from the cluster, three settings decide registration. The agent registers with the cluster named by ECS_CLUSTER in /etc/ecs/ecs.config, and with no value it joins the default cluster. The instance needs a container instance IAM role. Without an internet path, it needs the ecs-agent, ecs-telemetry and ecs interface endpoints in the same Region. If the instance did register but its agent is disconnected, see the agent guide. Agent configuration · Container instance role · ECS interface endpoints

An illustrative fixture#

This fixture is fictional. The cluster orders uses the capacity provider orders-cp with managed scaling on and targetCapacity 100, backed by the group orders-asg. A deployment of orders:58 with maximumPercent 200 leaves four tasks in PROVISIONING at 10:05.

In the first case the group reads min 2, max 4, desired 4, with four InService instances, all registered with provider orders-cp and full of old tasks. The last activity, at 10:01, launched the fourth instance successfully. ECS asked for more and the group has nowhere to go. Raise MaxSize to cover the overlap, or lower maximumPercent so the deployment needs fewer instances at once.

In the second case the group reads max 8 and desired 6, with six InService instances, and the activities are Successful. The cluster lists only four container instances. The two missing instances came from a new launch template version whose user data no longer writes ECS_CLUSTER=orders, so they registered in the default cluster. Running list-container-instances --cluster default shows them there. Restore the user data and replace the two instances.

Confirm on the replacement#

After the change, new instances should appear as ACTIVE container instances with agent true and provider set, the tasks should move from PROVISIONING through PENDING to RUNNING, and CapacityProviderReservation should return to targetCapacity. Read the group's desired against max afterwards. If the deployment's peak used the last of the headroom, the next one stops at the same place. Task lifecycle

Where the reading misleads#

Scale-out runs in steps. After a step, the group waits for new instances to pass instanceWarmupPeriod before the next one, so a large deployment can sit in PROVISIONING for several steps without anything being wrong. Read the activity times before you call it stuck. Cluster auto scaling

Each cluster can hold at most 500 tasks in PROVISIONING, a quota that applies only to tasks launched through an Auto Scaling group capacity provider and that many simultaneous deployments can reach. AWS recommends distinctInstance as the only placement constraint, because other constraints can stop the scale-out process when they do not match the instances it samples. A warm pool needs ECS_WARM_POOLS_CHECK=true in the agent configuration. ECS quotas · Cluster auto scaling · Warm pools

For services without a capacity provider, a full cluster leaves a placement event instead of waiting tasks; see the CPU and memory guide. For other layers, see the signature table.

Questions#

Why are my ECS tasks stuck in PROVISIONING?

With an Auto Scaling group capacity provider, tasks wait in PROVISIONING until an instance can hold them. If they never move, the group is at its maximum, the capacity provider is not scaling it, its launches fail, or new instances are not registering with the cluster.

Does ECS managed scaling change the Auto Scaling group's maximum size?

No. Cluster auto scaling changes the group's desired capacity within the minimum and maximum you set, so a group at MaxSize cannot add instances for waiting tasks.

Why do new EC2 instances not join my ECS cluster?

The agent joins the cluster named by ECS_CLUSTER, or default when it is unset, and it needs a container instance role and a network path to ECS. Find the instance in the default cluster or with a disconnected agent before changing the group.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading