oven-sh/bun · error

Failed to run instances: ${inspect(instanceOptions)}

Error message

Failed to run instances: ${inspect(instanceOptions)}

What it means

aws.runInstances() in scripts/machine.mjs retries `ec2 run-instances` several times with random backoff and then throws, dumping the instance options. It fires only after every attempt failed to return Instances, and it discards the underlying AWS error text — the real reason must be replayed manually.

Source

Thrown at scripts/machine.mjs:148

        throwOnError: error => {
          if (options["instance-market-options"] && /InsufficientInstanceCapacity/i.test(inspect(error))) {
            delete options["instance-market-options"];
            const instanceType = options["instance-type"] || "default";
            console.warn(`There is not enough capacity for ${instanceType} spot instances, retrying with on-demand...`);
            return false;
          }
          return true;
        },
      });
      if (result) {
        const { Instances } = result;
        if (Instances.length) {
          return Instances.sort((a, b) => (a.LaunchTime < b.LaunchTime ? 1 : -1));
        }
      }
      await new Promise(resolve => setTimeout(resolve, i * Math.random() * 15_000));
    }
    throw new Error(`Failed to run instances: ${inspect(instanceOptions)}`);
  },

  /**
   * @param {...string} instanceIds
   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/stop-instances.html
   */
  async stopInstances(...instanceIds) {
    await aws.spawn($`ec2 stop-instances --no-hibernate --force --instance-ids ${instanceIds}`);
  },

  /**
   * @param {...string} instanceIds
   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/terminate-instances.html
   */
  async terminateInstances(...instanceIds) {
    await aws.spawn($`ec2 terminate-instances --instance-ids ${instanceIds}`, {
      throwOnError: error => !/InvalidInstanceID\.NotFound/i.test(inspect(error)),
    });

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Replay the run-instances call manually with the printed instanceOptions to see the real AWS error
  2. Switch instance type or AZ (capacity), or set a fallback instance type
  3. Request a Service Quotas increase for the instance family
  4. Verify the AMI/subnet/securityGroupId exist in the target region

Example fix

// before
throw new Error(`Failed to run instances: ${inspect(instanceOptions)}`);

// after
throw new Error(`Failed to run instances: ${inspect(instanceOptions)}`, { cause: lastError });
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight the ingredients of run-instances so failures are explicit
const img = await $`aws ec2 describe-images --image-ids ${amiId} --query 'Images[0].State'`.text();
if (img.trim() !== 'available') throw new Error(`AMI ${amiId} not available`);
await $`aws service-quotas get-service-quota --service-code ec2 --quota-code L-1216C47A`.quiet();

Try / catch

try {
  const instances = await aws.runInstances(instanceOptions);
} catch (error) {
  const msg = String(error);
  if (/capacity|limit/i.test(msg)) {
    // switch instance type / region and retry once at the caller level
  } else {
    throw error; // config problems won't heal — surface them
  }
}

Prevention

When it happens

Trigger: InsufficientInstanceCapacity for the chosen instance type/AZ; account vCPU limit hit (Service Quotas); invalid AMI id, subnet, or security group for the region; credentials/region misconfiguration failing every retry identically.

Common situations: Spot/preemptible capacity dry spells in popular regions; a new region where the quota is still 0; AMI id copied from a different region; CI credentials rotated and now invalid.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/cd0c7ef5f00cd232. Report an issue: GitHub.