Learning center

ECS tasks fail to start during a deploy: subnet out of IP addresses

If an awsvpc service's new tasks fail before they run, compare each subnet's free IPv4 addresses with the tasks the deployment can run at its peak. A rolling deployment runs old and new tasks side by side, and every awsvpc task needs its own network interface and private address. A shortfall in the subnets, or in the network interfaces an EC2 container instance can attach, fails launches that the release itself did not cause.

The signature and its nearby causes#

The deployment of a new revision starts, some new tasks reach RUNNING, and others fail before their containers run. The failed tasks have no startedAt. In the signature table this is a startup failure, but three causes produce it, and only one is in the revision. The signature table

  • Subnet addresses. Each task that uses the awsvpc network mode receives its own elastic network interface, and each task interface gets a private IPv4 address by default. Fargate tasks always get a dedicated interface. When the subnets in the service's network configuration run out of free addresses, ECS cannot create the interface. AWS's troubleshooting page for TaskFailedToStart lists an EC2 error raised while creating the network interface, and points at the subnet's remaining addresses. Task networking · TaskFailedToStart errors
  • Interface attachment points on EC2. On the EC2 launch type, each task interface attaches to the container instance, and an instance type allows only a few. AWS's example is a c5.large that can attach three interfaces, one of them the primary, so it runs two awsvpc tasks. Here ECS usually places no task at all, and the service event reads service (SERVICE) was unable to place a task because no container instance met all of its requirements. with "Not enough available ENI attachment points" among the documented causes. ENI limits per instance · Service event messages
  • A change in the release. A different image, secret or log group also fails tasks before they run. The stopped reason then names that dependency instead of the network interface, and the startup section of the signature table covers them.

Compute the deployment's peak task count#

During a rolling deployment, maximumPercent caps the tasks in RUNNING or PENDING as a percentage of the desired count, rounded down. With a desired count of 4 and the default 200%, the scheduler may start four new tasks before it stops the four old ones, if resources allow. Each of those tasks holds one address until it stops, so the deployment's peak is desiredCount × maximumPercent / 100 addresses for this service alone. DeploymentConfiguration

Read the service's counts, its deployment settings and the subnets each deployment uses. Use a read-only profile and replace the uppercase placeholders.

aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{desired:desiredCount,running:runningCount,pending:pendingCount,maxPercent:deploymentConfiguration.maximumPercent,minPercent:deploymentConfiguration.minimumHealthyPercent,launch:launchType,capacity:capacityProviderStrategy[].capacityProvider,deployments:deployments[].{id:id,status:status,desired:desiredCount,running:runningCount,pending:pendingCount,failed:failedTasks,subnets:networkConfiguration.awsvpcConfiguration.subnets}}' \
  --output json --no-cli-pager

Then read the free addresses in each of those subnets. AvailableIpAddressCount is the number of unused private IPv4 addresses in the subnet; addresses held by stopped EC2 instances count as unavailable. Other workloads in the same subnets, such as other services, EC2 instances or Lambda functions attached to the VPC, draw from the same pool. Subnet fields · describe-subnets

aws ec2 describe-subnets \
  --profile PROFILE --region REGION --subnet-ids SUBNET_ID_1 SUBNET_ID_2 SUBNET_ID_3 \
  --query 'Subnets[].{subnet:SubnetId,az:AvailabilityZone,cidr:CidrBlock,free:AvailableIpAddressCount}' \
  --output table --no-cli-pager

Compare the extra addresses the deployment needs, the peak minus the tasks already running, with the sum of free. Read each subnet as well as the total: a subnet with almost no free addresses can fail some launches while launches in the other subnets succeed.

Finally, confirm the failed tasks match this cause. Group them by deployment and Availability Zone, and read the reason for a mention of the network interface or the subnet. Task fields

aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN_1 TASK_ARN_2 \
  --query 'tasks[].{deployment:startedBy,az:availabilityZone,created:createdAt,started:startedAt,code:stopCode,reason:stoppedReason}' \
  --output json --no-cli-pager

On EC2, read interface capacity instead#

When the service runs on EC2 container instances, the limit is often the instance before it is the subnet. With the awsvpcTrunking account setting turned on, supported instance types launched after the opt-in get a trunk interface and a higher limit: AWS's c5.large example rises from two awsvpc tasks to ten. Instances launched before the opt-in keep the default limit. Check the effective setting and which instances in the cluster carry a trunk. ENI trunking · list-account-settings · list-attributes

aws ecs list-account-settings \
  --profile PROFILE --region REGION --name awsvpcTrunking --effective-settings \
  --query 'settings[].{name:name,value:value,principal:principalArn}' \
  --output json --no-cli-pager

aws ecs list-attributes \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --target-type container-instance --attribute-name ecs.awsvpc-trunk-id \
  --query 'attributes[].targetId' --output json --no-cli-pager

A container instance missing from the second list runs at its instance type's default limit. A related placement cause on EC2 is a container instance that is not in any subnet the service names; AWS lists it under the missing-attribute cause of the same service event. Service event messages

What each result means#

ReadingMost likely causeNext step
Failed tasks have no startedAt, the reason names the network interface, and free addresses are below the extra tasks the deployment needsSubnet addressesAdd address space or lower the deployment's peak
No failed task for the new deployment; the service event says no container instance met the requirements; instances lack a trunkInterface attachment points on EC2Add instances, or opt in to trunking and replace the instances
Free addresses exceed the peak and the reason names an image, secret or log groupA change in the releaseFollow the startup cause the reason names

An illustrative deployment, two outcomes#

This fixture is fictional. The service orders runs 40 tasks on Fargate across three subnets, with the default maximumPercent of 200. The deployment ecs-svc/2211 for orders:58 may therefore run up to 80 tasks, 40 more than are running.

SubnetAvailability ZoneFree addresses at 09:57
subnet-0a1us-east-1a14
subnet-0b2us-east-1b3
subnet-0c3us-east-1c11

In the first outcome, only 28 addresses are free for 40 new tasks, and subnet-0b2 has 3. New tasks in us-east-1b stop with TaskFailedToStart and a reason about creating the network interface, and the deployment's failedTasks climbs. The free count recovers each time a failed task's interface is deleted, so a reading taken ten minutes later looks healthier than the subnet did at 09:58. orders:57 would have failed the same way had it been deployed that morning. The revision did not cause the failure, and rolling back starts another deployment that needs the same addresses.

In the second outcome, the three subnets have 140 free addresses, the new tasks in every zone stop with the same reason, and that reason names the awslogs log group in orders:58. Addresses are not the constraint, and the revision is.

What to change, and how to confirm#

Each of these is a change; make it through the service's usual configuration path.

  • Add address space. Add subnets with free addresses to the service's network configuration. A service can name up to 16 subnets, all in one VPC. AwsVpcConfiguration
  • Lower the peak. A lower maximumPercent starts fewer new tasks at once, and a minimumHealthyPercent below 100 lets the scheduler stop old tasks first. Both slow the rollout, and a lower minimum runs fewer tasks while it proceeds. Keep the pair able to stop or start at least one task, or the service reports that the deployment configuration blocks it. DeploymentConfiguration · Service event messages
  • Free addresses held elsewhere, after checking what holds them.

AWS's networking best practices recommend planning IP capacity for large awsvpc workloads before they run out. awsvpc best practices

On the next deployment, read describe-subnets during the rollout, not after it. The free count in each subnet should fall by about the number of new tasks there and stay above zero, the new deployment's tasks should all have startedAt, and failedTasks should stay at zero.

Where the reading stops#

AvailableIpAddressCount is the count at the moment you read it. Failed tasks release their interfaces during deprovisioning, and other workloads scale on their own, so a later reading can show plenty of free addresses in a subnet that was empty during the launch. Another workload in the same subnets reports the shortage in its own terms: a Lambda function attached to the VPC records SubnetOutOfIPAddresses as a state reason code, which corroborates a shortage at that time. Stopped tasks stay visible for at least an hour, so read them first. Task lifecycle · Lambda function states · Stopped task errors

The stopped reason is free text that AWS may reword, so key on TaskFailedToStart, the missing startedAt and the subnet reading together. Two other records raise the address count a rollout holds. A scale-out during the rollout adds tasks, which the auto scaling guide separates from the release, and protected old tasks keep their addresses until protection lapses, which the protected tasks guide covers. For stop codes other than TaskFailedToStart, read the stop code guide. If a deployment instead stays in progress with no failed tasks at all, that is a different question about placed and unplaced tasks.

Questions#

How many IP addresses does an ECS rolling deployment need?

Each awsvpc task holds one private IPv4 address. At its peak a rolling deployment can run the desired count times maximumPercent divided by 100, rounded down, so with the default 200% it can need twice the service's steady-state addresses.

Why do only some new ECS tasks fail with a network interface error?

ECS launches tasks across the subnets the service names, and each subnet has its own free count. A single nearly full subnet fails the launches that land in it while the other subnets succeed, so read AvailableIpAddressCount per subnet.

Does ENI trunking help Fargate tasks?

No. Trunking raises the interface limit for supported EC2 container instances. Fargate tasks always receive a dedicated interface, and their limit is the free addresses in the subnets.

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