{"record":{"id":"caabebe3c44f7cde","repo":"anomalyco/sst","slug":"the-number-of-elastic-ip-allocation-ids-must-match","errorCode":null,"errorMessage":"The number of Elastic IP allocation IDs must match the number of AZs.","messagePattern":"The number of Elastic IP allocation IDs must match the number of AZs\\.","errorType":"validation","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/vpc.ts","lineNumber":873,"sourceCode":"        if (nat === \"ec2\") {\n          return {\n            type: \"ec2\" as const,\n            ec2: { instance: \"t4g.nano\", ami: undefined, role: undefined },\n          };\n        }\n        if (nat) {\n          if (nat.ec2 && nat.type === \"managed\")\n            throw new VisibleError(\n              `The \"nat.type\" cannot be \"managed\" when \"nat.ec2\" is specified.`,\n            );\n\n          if (!nat.type && !nat.ec2)\n            throw new VisibleError(\n              `Missing \"nat.type\" for the \"${name}\" VPC. It is required when \"nat.ec2\" is not specified.`,\n            );\n\n          if (nat.ip && nat.ip.length !== zones.length)\n            throw new VisibleError(\n              `The number of Elastic IP allocation IDs must match the number of AZs.`,\n            );\n\n          return nat.ec2 || nat.type === \"ec2\"\n            ? {\n                type: \"ec2\" as const,\n                ip: nat.ip,\n                ec2: {\n                  instance: nat.ec2?.instance ?? \"t4g.nano\",\n                  ami: nat.ec2?.ami,\n                  role: nat.ec2?.role,\n                },\n              }\n            : {\n                type: \"managed\" as const,\n                ip: nat.ip,\n              };\n        }","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/vpc.ts#L855-L891","documentation":"Thrown by normalizeNat when `nat.ip` (an array of Elastic IP allocation IDs for NAT gateways) does not have exactly one allocation ID per availability zone in the VPC. Each AZ's NAT gateway needs its own EIP, so the lengths must match.","triggerScenarios":"Creating a multi-AZ VPC (e.g. 3 zones) with `{ nat: { ip: [\"eipalloc-1\", \"eipalloc-2\"] } }` (2 IPs), or specifying IPs for a single-AZ VPC count mismatch.","commonSituations":"Hard-coding IPs from a previous 2-AZ config then adding a zone; typos or duplicate entries in the allocation ID array; forgetting to add an EIP after increasing the zones count.","solutions":["Count the AZs (zones array length) and provide exactly one EIP allocation ID per zone.","Create additional Elastic IPs in EC2 and add their allocation IDs to nat.ip.","Reduce the number of zones if you intentionally want fewer NAT gateways."],"exampleFix":"// before (3 zones, 2 EIPs)\nnew sst.aws.Vpc(\"MyVPC\", { zones: 3, nat: { type: \"managed\", ip: [\"eipalloc-1\", \"eipalloc-2\"] } });\n// after\nnew sst.aws.Vpc(\"MyVPC\", { zones: 3, nat: { type: \"managed\", ip: [\"eipalloc-1\", \"eipalloc-2\", \"eipalloc-3\"] } });","handlingStrategy":"validation","validationCode":"const zoneCount = args.zones ?? 2;\nif (args.nat?.ip && args.nat.ip.length !== zoneCount)\n  throw new Error(`nat.ip needs exactly ${zoneCount} EIP allocation IDs (one per AZ).`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate EIPs programmatically so the count always matches zones","Recount nat.ip whenever changing the zones value","Keep a comment linking zones count to the ip array"],"tags":["vpc","nat","elastic-ip","config-validation","aws"],"backgroundTag":"eip-az-count-mismatch","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}