{"record":{"id":"e43040a6eed9a516","repo":"oven-sh/bun","slug":"failed-to-find-available-image-imageid","errorCode":null,"errorMessage":"Failed to find available image: ${imageId}","messagePattern":"Failed to find available image: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":351,"sourceCode":"   */\n  async getAvailableImage(imageOrImageId) {\n    let imageId = imageOrImageId;\n    if (typeof imageOrImageId === \"object\") {\n      const { ImageId, State } = imageOrImageId;\n      if (State === \"available\") {\n        return imageOrImageId;\n      }\n      imageId = ImageId;\n    }\n\n    await aws.waitImage(\"image-available\", imageId);\n    const [availableImage] = await aws.describeImages({\n      \"state\": \"available\",\n      \"image-id\": imageId,\n    });\n\n    if (!availableImage) {\n      throw new Error(`Failed to find available image: ${imageId}`);\n    }\n\n    return availableImage;\n  },\n\n  /**\n   * @param {MachineOptions} options\n   * @returns {Promise<AwsImage>}\n   */\n  async getBaseImage(options) {\n    const { os, arch, distro, release } = options;\n\n    let name, owner;\n    if (os === \"linux\") {\n      if (!distro || distro === \"debian\") {\n        owner = \"amazon\";\n        name = `debian-${release || \"*\"}-${arch === \"aarch64\" ? \"arm64\" : \"amd64\"}-*`;\n      } else if (distro === \"ubuntu\") {","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L333-L369","documentation":"getAvailableImage() waits for an AMI to become available (`ec2 wait image-available`), then re-describes it filtered to state=available; the error means the image id is no longer listed as available — it failed to build, was deregistered, or the describe filters (owner) no longer match.","triggerScenarios":"The pending image transitioned to 'failed' after the waiter returned; a concurrent CI job deregistered the AMI between wait and describe; describing with an owner filter that excludes the image's actual owner.","commonSituations":"Packer/EC2 image bake failed mid-way leaving a dead AMI id; overlapping publish pipelines deregistering each other's images.","solutions":["Check the image's real state: `aws ec2 describe-images --image-ids <id> --region <region>` (State: available/failed/pending)","If State is 'failed', rebuild the image from scratch","Avoid concurrent jobs that deregister the same AMI","Retry after a short delay if it was pure consistency lag"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const state = await $`aws ec2 describe-images --image-ids ${imageId} --query 'Images[0].State'`.text();\nif (state.trim() === 'failed') {\n  throw new Error(`AMI ${imageId} failed to build — rebuild it instead of waiting`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never deregister an AMI another job may be waiting on — serialize publish pipelines","After `ec2 wait image-available`, re-check State rather than assuming success","Treat 'failed' images as rebuild-worthy, not retry-worthy"],"tags":["aws","ec2","ami","ci"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}