{"record":{"id":"d453439ed8c963fb","repo":"anomalyco/sst","slug":"the-dns-record-partial-name-cannot-be-created","errorCode":null,"errorMessage":"The DNS record \"${partial.name}\" cannot be created because the domain name does not match the hosted zone \"${zone.name}\" (${zoneId}).","messagePattern":"The DNS record \"(.+?)\" cannot be created because the domain name does not match the hosted zone \"(.+?)\" \\((.+?)\\)\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/dns.ts","lineNumber":186,"sourceCode":"  }\n\n  function _createRecord(\n    namePrefix: string,\n    partial: Omit<route53.RecordArgs, \"zoneId\">,\n    opts: ComponentResourceOptions,\n  ) {\n    return output(partial).apply((partial) => {\n      const nameSuffix = logicalName(partial.name);\n      const zoneId = lookupZone();\n      const dnsRecord = createRecord();\n      return dnsRecord;\n\n      function lookupZone() {\n        if (args.zone) {\n          return output(args.zone).apply(async (zoneId) => {\n            const zone = await route53.getZone({ zoneId });\n            if (!partial.name.replace(/\\.$/, \"\").endsWith(zone.name)) {\n              throw new VisibleError(\n                `The DNS record \"${partial.name}\" cannot be created because the domain name does not match the hosted zone \"${zone.name}\" (${zoneId}).`,\n              );\n            }\n            return zoneId;\n          });\n        }\n\n        return new HostedZoneLookup(\n          `${namePrefix}${partial.type}ZoneLookup${nameSuffix}`,\n          {\n            domain: output(partial.name!).apply((name) =>\n              name.replace(/\\.$/, \"\"),\n            ),\n          },\n          opts,\n        ).zoneId;\n      }\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/dns.ts#L168-L204","documentation":"When creating a DNS record, SST resolves the Route53 hosted zone (either explicitly given via `args.zone` or auto-discovered). This VisibleError is thrown in lookupZone when the record's domain name is not a subdomain of the hosted zone's name, meaning the record cannot live in that zone.","triggerScenarios":"`args.zone` is set to a zoneId whose zone name (from `route53.getZone`) does not suffix-match `partial.name` after stripping a trailing dot — e.g. record `api.example.com` in a zone for `other.com`.","commonSituations":"Passing the wrong hosted zone ID in a custom domain config; a typo in the domain or zone name; the domain registered in Route53 differs from the domain being configured (e.g. www vs apex or a staging domain); DNS records defined in a shared helper that receives mismatched domain/zone values.","solutions":["Correct the domain name in the record so it matches (is a subdomain of) the hosted zone name","Verify `args.zone` points to the hosted zone ID for the actual domain — check with `aws route53 list-hosted-zones`","Remove the explicit `zone` argument and let SST auto-discover the zone from the record's domain","If the domain is not in Route53 at all, either register/transfer it to Route53 or use your registrar's DNS instead of SST's Route53 DNS-validated component"],"exampleFix":"// before\nnew sst.aws.DnsRecord(\"Cname\", {\n  name: \"api.example.com\",\n  type: \"CNAME\",\n  value: target,\n  zone: \"Z0123456789OTHER\", // zone for other.com\n});\n// after\nnew sst.aws.DnsRecord(\"Cname\", {\n  name: \"api.example.com\",\n  type: \"CNAME\",\n  value: target,\n  zone: \"Z0123456789EXAMPLE\", // zone for example.com\n});","handlingStrategy":"validation","validationCode":"import { Route53 } from \"aws-sdk\"; // or use aws cli output\nasync function zoneMatches(record: string, zoneId: string) {\n  const zone = await new Route53().getZone({ Id: zoneId }).promise();\n  return record.replace(/\\.$/, \"\").endsWith(zone.Name!.replace(/\\.$/, \"\"));\n}","typeGuard":"function isSubdomainOf(record: string, zoneName: string): boolean {\n  return record.replace(/\\.$/, \"\").endsWith(zoneName.replace(/\\.$/, \"\"));\n}","tryCatchPattern":"try {\n  new sst.aws.DnsRecord(\"Cname\", { name, type: \"CNAME\", value, zone: zoneId });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"does not match the hosted zone\")) {\n    console.error(`Record ${name} does not belong to zone ${zoneId}; fix the domain or the zone id`);\n  } else throw e;\n}","preventionTips":["Verify hosted zone IDs with `aws route53 list-hosted-zones` before hardcoding them","Keep record domains and zone ids sourced from the same config constant","Omit `zone` and let SST auto-discover the zone when possible","Ensure the domain's DNS is actually hosted in Route53 before using Route53 DNS components"],"tags":["dns","route53","aws","validation","domain"],"backgroundTag":"dns-zone-mismatch","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}