{"record":{"id":"eaa9843974b5b5ac","repo":"oven-sh/bun","slug":"failed-to-get-password-data-for-instance-instan","errorCode":null,"errorMessage":"Failed to get password data for instance: ${instanceId}","messagePattern":"Failed to get password data for instance: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":197,"sourceCode":"\n  /**\n   * @param {string} instanceId\n   * @param {string} privateKeyPath\n   * @param {object} [passwordOptions]\n   * @param {boolean} [passwordOptions.wait]\n   * @returns {Promise<string | undefined>}\n   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/get-password-data.html\n   */\n  async getPasswordData(instanceId, privateKeyPath, passwordOptions = {}) {\n    const attempts = passwordOptions.wait ? 15 : 1;\n    for (let i = 0; i < attempts; i++) {\n      const { PasswordData } = await aws.spawn($`ec2 get-password-data --instance-id ${instanceId}`);\n      if (PasswordData) {\n        return decryptPassword(PasswordData, privateKeyPath);\n      }\n      await new Promise(resolve => setTimeout(resolve, 60000 * i));\n    }\n    throw new Error(`Failed to get password data for instance: ${instanceId}`);\n  },\n\n  /**\n   * @typedef AwsImage\n   * @property {string} ImageId\n   * @property {string} Name\n   * @property {string} State\n   * @property {string} CreationDate\n   */\n\n  /**\n   * @param {Record<string, string | undefined>} [options]\n   * @returns {Promise<AwsImage[]>}\n   * @link https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/describe-images.html\n   */\n  async describeImages(options = {}) {\n    const { [\"owner-alias\"]: owners, ...filterOptions } = options;\n    const filters = aws.getFilters(filterOptions);","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L179-L215","documentation":"getPasswordData() polls `ec2 get-password-data` for a Windows instance (15 attempts with 60s*i growing backoff when passwordOptions.wait is set, otherwise 1) and throws when PasswordData is still empty after the last attempt — i.e. Windows never made the admin password retrievable in time.","triggerScenarios":"Windows still sysprepping/booting past the total wait window; the instance was launched without a key pair so no encrypted password is ever produced; instance boot failure (host issue) so the agent never runs; calling with a non-Windows instanceId.","commonSituations":"Slow or overloaded EC2 host making first boot exceed an hour; image bake where getSecret key path and instance key pair don't correspond; passing wait:false and calling too early.","solutions":["Wait a few minutes and re-run the operation — the password often appears late in boot","Pass passwordOptions.wait = true to use all 15 backoff attempts","Verify the instance is Windows and was launched with the same key pair whose private key you are decrypting with","Check the instance's console screenshot / system log for boot failure if it never succeeds"],"exampleFix":"// before\nconst password = await aws.getPasswordData(instanceId, privateKeyPath);\n\n// after\nconst password = await aws.getPasswordData(instanceId, privateKeyPath, { wait: true });","handlingStrategy":"retry","validationCode":"// Only Windows instances launched with a key pair ever return password data\nconst desc = await $`aws ec2 describe-images --image-ids ${resolvedAmi} --query 'Images[0].Platform'`.text();\nif (desc.trim() !== 'windows') throw new Error('getPasswordData only works for Windows instances');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass { wait: true } when fetching Windows password data right after launch","Budget for first boot: Windows sysprep can take tens of minutes","Verify the instance was launched with the key pair you hold the private half of"],"tags":["aws","ec2","windows","provisioning"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}