{"record":{"id":"cd0c7ef5f00cd232","repo":"oven-sh/bun","slug":"failed-to-run-instances-inspect-instanceoptions","errorCode":null,"errorMessage":"Failed to run instances: ${inspect(instanceOptions)}","messagePattern":"Failed to run instances: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":148,"sourceCode":"        throwOnError: error => {\n          if (options[\"instance-market-options\"] && /InsufficientInstanceCapacity/i.test(inspect(error))) {\n            delete options[\"instance-market-options\"];\n            const instanceType = options[\"instance-type\"] || \"default\";\n            console.warn(`There is not enough capacity for ${instanceType} spot instances, retrying with on-demand...`);\n            return false;\n          }\n          return true;\n        },\n      });\n      if (result) {\n        const { Instances } = result;\n        if (Instances.length) {\n          return Instances.sort((a, b) => (a.LaunchTime < b.LaunchTime ? 1 : -1));\n        }\n      }\n      await new Promise(resolve => setTimeout(resolve, i * Math.random() * 15_000));\n    }\n    throw new Error(`Failed to run instances: ${inspect(instanceOptions)}`);\n  },\n\n  /**\n   * @param {...string} instanceIds\n   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/stop-instances.html\n   */\n  async stopInstances(...instanceIds) {\n    await aws.spawn($`ec2 stop-instances --no-hibernate --force --instance-ids ${instanceIds}`);\n  },\n\n  /**\n   * @param {...string} instanceIds\n   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/terminate-instances.html\n   */\n  async terminateInstances(...instanceIds) {\n    await aws.spawn($`ec2 terminate-instances --instance-ids ${instanceIds}`, {\n      throwOnError: error => !/InvalidInstanceID\\.NotFound/i.test(inspect(error)),\n    });","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L130-L166","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replay the run-instances call manually with the printed instanceOptions to see the real AWS error","Switch instance type or AZ (capacity), or set a fallback instance type","Request a Service Quotas increase for the instance family","Verify the AMI/subnet/securityGroupId exist in the target region"],"exampleFix":"// before\nthrow new Error(`Failed to run instances: ${inspect(instanceOptions)}`);\n\n// after\nthrow new Error(`Failed to run instances: ${inspect(instanceOptions)}`, { cause: lastError });","handlingStrategy":"retry","validationCode":"// Pre-flight the ingredients of run-instances so failures are explicit\nconst img = await $`aws ec2 describe-images --image-ids ${amiId} --query 'Images[0].State'`.text();\nif (img.trim() !== 'available') throw new Error(`AMI ${amiId} not available`);\nawait $`aws service-quotas get-service-quota --service-code ec2 --quota-code L-1216C47A`.quiet();","typeGuard":null,"tryCatchPattern":"try {\n  const instances = await aws.runInstances(instanceOptions);\n} catch (error) {\n  const msg = String(error);\n  if (/capacity|limit/i.test(msg)) {\n    // switch instance type / region and retry once at the caller level\n  } else {\n    throw error; // config problems won't heal — surface them\n  }\n}","preventionTips":["Keep a fallback instance type list for CI machines","Check vCPU quotas per family per region before scaling up agents","Never reuse AMI ids across regions — resolve per region"],"tags":["aws","ec2","ci","capacity"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}