AWS
EC2InsufficientInstanceCapacity - EC2 Insufficient Instance Capacity
Getting an **EC2InsufficientInstanceCapacity** error means AWS doesn't have enough available capacity in the Availability Zone you requested to fulfill your instance launch—this is a temporary capacity issue, not a quota limit. This server-side error (5xx) happens when AWS validates instance capacity availability. Most common when Availability Zone capacity is exhausted, but also appears when requested instance types are unavailable, high demand occurs in the region, Spot instance capacity is insufficient, or dedicated host capacity is unavailable.
#Common Causes
- →Identity: IAM service capacity issue. Service Control Policy (SCP) service capacity constraints. Account-level capacity restrictions.
- →Network: VPC endpoint EC2 capacity restrictions. Regional capacity constraints. Availability Zone capacity exhausted.
- →Limits: Availability Zone capacity exhausted. Requested instance type unavailable. High demand in the region. Spot instance capacity insufficient. Dedicated host capacity unavailable.
✓Solutions
- 1Step 1: Diagnose - Check which Availability Zone failed: Review error message for specific AZ. Verify if issue is AZ-specific or region-wide.
- 2Step 2: Diagnose - Check available instance types in AZ: aws ec2 describe-instance-type-offerings --location-type availability-zone --filters "Name=location,Values=us-east-1a" --query 'InstanceTypeOfferings[*].InstanceType' --output table. Verify if instance type is available.
- 3Step 3: Diagnose - Try different Availability Zone: Launch in different AZ: aws ec2 run-instances --image-id ami-XXXXX --instance-type t3.medium --placement AvailabilityZone=us-east-1b. Or try different instance type.
- 4Step 4: Fix - Try different Availability Zones: Loop through AZs: for az in us-east-1a us-east-1b us-east-1c; do aws ec2 run-instances --availability-zone $az ...; done. Or request different instance type.
- 5Step 5: Fix - Use Spot Instances or wait: Use Spot Instances for flexible capacity: aws ec2 request-spot-instances --spot-price "0.05" --instance-count 1. Or wait and retry. Use On-Demand Capacity Reservations for guaranteed capacity.
</>Code Examples
Try Launching in Different Availability Zones
1#!/bin/bash
2AMI_ID="ami-12345678"
3INSTANCE_TYPE="t3.medium"
4KEY_NAME="my-key-pair"
5
6AVAILABILITY_ZONES=("us-east-1a" "us-east-1b" "us-east-1c" "us-east-1d")
7
8echo "=== Trying Different Availability Zones ==="
9for ZONE in "${AVAILABILITY_ZONES[@]}"; do
10 echo "\nTrying Availability Zone: ${ZONE}"
11
12 aws ec2 run-instances \
13 --image-id ${AMI_ID} \
14 --instance-type ${INSTANCE_TYPE} \
15 --placement AvailabilityZone=${ZONE} \
16 --key-name ${KEY_NAME} \
17 --count 1 2>&1
18
19 if [ $? -eq 0 ]; then
20 echo "✓ Successfully launched in ${ZONE}"
21 break
22 else
23 echo "✗ Failed in ${ZONE} (EC2InsufficientInstanceCapacity)"
24 echo "Trying next Availability Zone..."
25 fi
26doneCheck Available Instance Types in Availability Zone
1#!/bin/bash
2AZ="us-east-1a"
3
4echo "=== Available Instance Types in ${AZ} ==="
5aws ec2 describe-instance-type-offerings \
6 --location-type availability-zone \
7 --filters "Name=location,Values=${AZ}" \
8 --query 'InstanceTypeOfferings[*].InstanceType' \
9 --output table
10
11echo "\n=== Check Specific Instance Type ==="
12INSTANCE_TYPE="t3.medium"
13OFFERING=$(aws ec2 describe-instance-type-offerings \
14 --location-type availability-zone \
15 --filters "Name=location,Values=${AZ}" "Name=instance-type,Values=${INSTANCE_TYPE}" \
16 --query 'InstanceTypeOfferings[0].InstanceType' \
17 --output text)
18
19if [ ! -z "${OFFERING}" ]; then
20 echo "✓ ${INSTANCE_TYPE} available in ${AZ}"
21else
22 echo "✗ ${INSTANCE_TYPE} not available in ${AZ}"
23 echo "Try different instance type or Availability Zone"
24fiUse Spot Instances for Flexible Capacity
1#!/bin/bash
2echo "=== Requesting Spot Instances ==="
3echo "Spot Instances provide flexible capacity when On-Demand is unavailable"
4
5# Create launch specification
6cat > launch-spec.json <<EOF
7{
8 "ImageId": "ami-12345678",
9 "InstanceType": "t3.medium",
10 "KeyName": "my-key-pair",
11 "SecurityGroupIds": ["sg-12345678"],
12 "SubnetId": "subnet-12345678"
13}
14EOF
15
16echo "\n=== Request Spot Instance ==="
17aws ec2 request-spot-instances \
18 --spot-price "0.05" \
19 --instance-count 1 \
20 --type "one-time" \
21 --launch-specification file://launch-spec.json \
22 --output json
23
24echo "\n=== Benefits of Spot Instances ==="
25echo "1. Lower cost (up to 90% discount)"
26echo "2. Flexible capacity when On-Demand unavailable"
27echo "3. Good for fault-tolerant workloads"
28echo "4. Can be interrupted with 2-minute notice"↗Related Errors
Provider Information
This error code is specific to AWS services. For more information, refer to the official AWS documentation.