{"record":{"id":"2004b179eb1c0edf","repo":"anomalyco/sst","slug":"could-not-find-hosted-zone-for-domain-s","errorCode":null,"errorMessage":"could not find hosted zone for domain %s","messagePattern":"could not find hosted zone for domain (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/aws-hosted-zone-lookup.go","lineNumber":85,"sourceCode":"\t\tzones = append(zones, res.HostedZones...)\n\n\t\tif res.NextMarker == nil {\n\t\t\tbreak\n\t\t}\n\t\tnextMarker = res.NextMarker\n\t}\n\n\tparts := strings.Split(domain, \".\")\n\tfor i := 0; i <= len(parts)-2; i++ {\n\t\tzoneName := strings.Join(parts[i:], \".\") + \".\"\n\t\tfor _, zone := range zones {\n\t\t\tif *zone.Name == zoneName {\n\t\t\t\treturn strings.TrimPrefix(*zone.Id, \"/hostedzone/\"), nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn \"\", fmt.Errorf(\"could not find hosted zone for domain %s\", domain)\n}\n","sourceCodeStart":67,"sourceCodeEnd":87,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/aws-hosted-zone-lookup.go#L67-L87","documentation":"This resource resolves the Route53 hosted zone ID for a custom domain by listing all zones in the account and matching the domain or its parent domains (walking up labels). If no zone's name matches any suffix of the domain, lookup fails with this error, blocking Create/Update of DNS-dependent resources.","triggerScenarios":"`lookup` is called with a domain whose zone doesn't exist in the current AWS account — the domain has no hosted zone, the zone lives in a different account, the zone name has extra/missing trailing-dot normalization, or the domain is a subdomain whose zone wasn't delegated.","commonSituations":"Typo in `customDomain` in `sst.config.ts`; domain registered in another AWS account or at an external registrar with no Route53 zone; zone deleted after being referenced; using a subdomain like `api.example.com` when only `example.com` zone exists in a different account.","solutions":["Create a Route53 hosted zone for the domain (or its parent) in the same AWS account used for deploy","Fix the `domainName` in your component's `customDomain` config to exactly match the zone","Verify with `aws route53 list-hosted-zones` that the zone exists under the credentials SST uses","Point your AWS_PROFILE/account to the one that owns the zone, then redeploy"],"exampleFix":"// before (sst.config.ts)\ncustomDomain: \"api.exmaple.com\"\n// after\ncustomDomain: \"api.example.com\"","handlingStrategy":"validation","validationCode":"// verify the zone exists under the deploy credentials BEFORE deploy\nimport { Route53Client, ListHostedZonesCommand } from \"@aws-sdk/client-route-53\";\nconst r53 = new Route53Client({});\nconst zones = await r53.send(new ListHostedZonesCommand({}));\nconst ok = zones.HostedZones.some(z => z.Name === \"example.com.\");\nif (!ok) throw new Error(\"hosted zone for domain missing in this AWS account\");","typeGuard":"function hasZoneForDomain(zones, domain) {\n  const parts = domain.split(\".\");\n  return parts.some((_, i) =>\n    zones.some(z => z.Name === parts.slice(i).join(\".\") + \".\")\n  );\n}","tryCatchPattern":"try {\n  await run(\"sst\", [\"deploy\"]);\n} catch (e) {\n  const m = /could not find hosted zone for domain (.+)/.exec(String(e));\n  if (m) {\n    throw new Error(`Create a Route53 hosted zone for ${m[1]} in the deploy account, or fix customDomain config`, { cause: e });\n  }\n  throw e;\n}","preventionTips":["Run `aws route53 list-hosted-zones` with the same profile SST uses before adding custom domains","Double-check customDomain spelling and TLD in sst.config.ts","Register/transfer the zone into the deploy AWS account","For subdomains, ensure a parent zone exists and NS records delegate correctly"],"tags":["aws","route53","dns","hosted-zone","custom-domain"],"backgroundTag":"hosted-zone-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}