# InsufficientInstanceCapacity on EC2: what it means, what it is not, and how to get out by rotating zone or type

`InsufficientInstanceCapacity` on EC2 means AWS does not have enough On-Demand capacity right now for the instance type you asked for in that Availability Zone. It is not your quota and not a configuration mistake: the account can have plenty of vCPUs left and the launch still fails. AWS recommends waiting a few minutes and retrying, asking for fewer instances per request, not pinning the zone, or trying another instance type. If the capacity has to be there no matter what, the way out is an On-Demand Capacity Reservation.

```
We currently do not have sufficient <instance type> capacity in the Availability Zone you requested (<requested Availability Zone>). Our system will be working on provisioning additional capacity. You can currently get <instance type> capacity by not specifying an Availability Zone in your request or choosing <list of Availability Zones that currently supports the instance type>.
```

That is the message as AWS documents it in the Auto Scaling guide; the angle brackets are replaced by the type, the requested zone and the zones that have capacity at that moment. The AWS CLI prints errors in the format `An error occurred (<code>) when calling the <operation> operation: <message>`, and here the code is `InsufficientInstanceCapacity`. Read the end of the message first: the list of zones already tells you where there is room.

## Where it shows up: launch, start, reserve, Auto Scaling and Terraform

- `aws ec2 run-instances` (the RunInstances API, from the CLI, an SDK or the console): when launching a new instance.
- `aws ec2 start-instances` on a stopped instance: the other case AWS documents. When you stop and start an instance, AWS moves it to new hardware, so an instance that ran yesterday may not start again today.
- Capacity Reservations: according to the API error code list, it can also show up when creating or modifying a capacity reservation.
- Auto Scaling: the group activity shows "Launching EC2 instance failed." with the message above, and the group keeps looking for capacity in its other enabled zones.
- Terraform: the `aws_instance` resource calls RunInstances, and the AWS provider code only retries IAM propagation errors there. With this error the apply stops with `creating EC2 Instance: ...` and you have to run it again. It is one more case of [what the plan does not check](https://controlcloud.dev/en/blog/terraform-plan-verde-apply-rojo-lo-que-plan-no-verifica).

## What it is not: quota and Unsupported

Two similar errors have a different cause, and waiting fixes neither:

- Quota: `InstanceLimitExceeded` ("You've reached the limit on the number of instances you can run concurrently") and `VcpuLimitExceeded` (you hit the vCPU limit for running On-Demand instances). These are limits on your account per Region. On-Demand quotas are measured in vCPUs per group of instance families, and stopped instances do not count. You fix them by requesting a quota increase or freeing usage.
- `Unsupported`: "The requested configuration is currently not supported. Please check the documentation for supported configurations." The instance type or purchasing option is not offered in that Region or zone. AWS says to try a different configuration.

To rule them out before retrying: the quota for the standard families (A, C, D, H, I, M, R, T, Z) and the zones where the type you want is offered:

```
# On-Demand vCPU quota for the standard families
aws service-quotas get-service-quota --service-code ec2 --quota-code L-1216C47A

# zones in the Region that offer the type
aws ec2 describe-instance-type-offerings --location-type availability-zone \
  --filters Name=instance-type,Values=m6i.large \
  --query "InstanceTypeOfferings[].Location"
```

## What AWS recommends

- Wait a few minutes and submit the request again: according to AWS, capacity shifts frequently.
- Ask for fewer instances per request: instead of launching 15 in one, make 3 requests of 5 or 15 of 1.
- Launch without specifying an Availability Zone, so EC2 picks one.
- Try a different instance type; you can change the type later. To change it, the instance has to be stopped and the new type has to be compatible with its configuration: `aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --instance-type "{\"Value\": \"m5.large\"}"`.
- In Auto Scaling: add zones to the group and use several instance types so you do not depend on a single one.
- If you launch into a cluster placement group, AWS warns you can get this error there too.

Two practical details. Each subnet lives in a single Availability Zone, so choosing a subnet is choosing a zone: rotating zones means rotating subnets, and "not specifying a zone" only applies if you do not pin the subnet. And for a stopped instance that will not start, what is left is waiting and retrying the start, or changing its type (it is already stopped) and starting it with the new one.

## If you need a guarantee: On-Demand Capacity Reservations

A Capacity Reservation reserves EC2 capacity in a specific Availability Zone for as long as you want. Immediate-use reservations have no term commitment and can be canceled at any time. By default, instances with matching attributes (type, platform, zone and tenancy) run in the reservation automatically.

```
aws ec2 create-capacity-reservation \
  --instance-type m6i.large --instance-platform Linux/UNIX \
  --availability-zone us-east-1a --instance-count 1 \
  --end-date-type unlimited
```

Three things before creating one: it is charged at the equivalent On-Demand rate whether you run instances in it or not; it counts toward your On-Demand quota even if unused; and creating it can fail with the same `InsufficientInstanceCapacity`, so create it before you need it, not in the middle of the problem.

## A short loop that rotates zone and type

Before leaving it running, rule out quota and `Unsupported` with the commands above. The loop tries each type in each subnet (one per zone), stops at the first successful launch, moves on when the error is capacity or the type is not offered in that zone, and stops on any other error, because rotating will not fix it. Fill in the AMI, the subnets and types that suit your workload:

```
AMI=ami-0abcdef1234567890
SUBNETS="subnet-aaaa1111 subnet-bbbb2222 subnet-cccc3333"   # one per zone
TYPES="m6i.large m5.large m7i.large"
for t in $TYPES; do
  for s in $SUBNETS; do
    if out=$(aws ec2 run-instances --image-id "$AMI" --instance-type "$t" \
        --subnet-id "$s" --count 1 \
        --query 'Instances[0].InstanceId' --output text 2>&1); then
      echo "launched $out: $t in $s"; break 2
    fi
    case "$out" in
      *InsufficientInstanceCapacity*) echo "no capacity: $t in $s" ;;
      *Unsupported*) echo "not offered: $t in $s" ;;
      *) echo "$out"; break 2 ;;
    esac
  done
done
```

If no pair works, wait a few minutes and run it again, which is the first thing AWS recommends. The same problem on other clouds has its own note: [AllocationFailed on Azure](https://controlcloud.dev/en/blog/azure-allocationfailed-skunotavailable-cuota-vcpu) and ["Out of host capacity" on OCI, with its retry loop](https://controlcloud.dev/en/blog/oci-out-of-host-capacity-a1-flex-retry-loop).

## Frequently asked questions about InsufficientInstanceCapacity

What does InsufficientInstanceCapacity mean? That AWS has no On-Demand capacity available right now to fulfill your request: that instance type, in that zone, in that quantity. The API error code list sums it up as "There is not enough capacity to fulfill your request".

Is it a problem with my quota or my account? No. The quota errors are `InstanceLimitExceeded` and `VcpuLimitExceeded`. A quota increase does not fix this error, and having free quota does not guarantee capacity.

How long do I have to wait? AWS gives no time frame: it says to wait a few minutes because capacity shifts frequently, and the message adds that it is working on provisioning more. If you cannot wait, switch zone or type.

Why will my stopped instance not start when it ran yesterday? Because stopping and starting moves it to new hardware, and starting a stopped instance is one of the cases where AWS documents this error. Wait and retry the start, or change its type while it is stopped.

Does a Capacity Reservation prevent it? Yes, once it exists: the capacity is held in that zone. But it is charged even if you do not use it, it counts toward your On-Demand quota, and creating it can also fail with this error if there is no room at that moment.

## Sources

- Amazon EC2 User Guide, "Troubleshoot Amazon EC2 instance launch issues" (InsufficientInstanceCapacity, InstanceLimitExceeded, Unsupported and the recommended solutions).
- Amazon EC2 API Reference, "Error codes for the Amazon EC2 API" (InsufficientInstanceCapacity when creating or modifying Capacity Reservations, InstanceLimitExceeded, VcpuLimitExceeded, Unsupported).
- Amazon EC2 Auto Scaling User Guide, "Troubleshoot Amazon EC2 Auto Scaling: EC2 instance launch failures" (the message text and what to do in a group).
- Amazon EC2 User Guide: On-Demand Instance quotas, changing the instance type, On-Demand Capacity Reservations and their billing. Amazon VPC User Guide: subnets.
- AWS CLI references: `run-instances`, `create-capacity-reservation`, `describe-instance-type-offerings`, `modify-instance-attribute` and `service-quotas get-service-quota`; the AWS CLI troubleshooting guide (error format).
- Terraform AWS provider code (`internal/service/ec2/ec2_instance.go`): what it retries when creating an `aws_instance`.

