如何为Route53域名正确添加DNS记录?API参数适配疑问
Hey there, let's get this sorted out quickly—you're trying to use the wrong AWS API for your task!
The updateDomainNameservers API you referenced is only for changing the authoritative nameservers associated with your domain (like switching from Route53's default NS servers to a third-party DNS provider). It has nothing to do with adding individual DNS records (like your A record) to a Route53 hosted zone.
Correct API to Use: ChangeResourceRecordSets
To add your root (@) A record, you need to use Route53's ChangeResourceRecordSets API instead. Here's the parameter template tailored exactly to your needs:
var params = { HostedZoneId: 'YOUR_ROUTE53_HOSTED_ZONE_ID', // Replace with your hosted zone ID (find this in Route53 console) ChangeBatch: { Comment: 'Adding root A record for my domain', Changes: [ { Action: 'CREATE', // Use 'UPSERT' instead if you want to overwrite an existing root A record ResourceRecordSet: { Name: 'yourdomain.com', // "@" translates to your full root domain (e.g., example.com) Type: 'A', TTL: 300, // Replace with your desired TTL value ResourceRecords: [ { Value: '192.168.1.1' // Replace with your target IP address } ] } } ] } };
Key Notes to Keep in Mind:
- HostedZoneId: You must specify the ID of the Route53 hosted zone linked to your domain. You can grab this from the Route53 console's "Hosted Zones" section.
- Action: Use
CREATEif this is a brand-new record. If there's already a root A record and you want to update it, useUPSERT(it will create the record if it doesn't exist, or update it if it does). - Name: The
@in DNS records refers to the root domain, so you need to input your full domain name here (not just "@").
Critical Warning:
Don't use the updateDomainNameservers API for this task! Modifying your domain's nameservers will redirect all DNS queries for your domain to a new set of servers—this would break all existing DNS records unless you've fully migrated them to the new nameservers.
内容的提问来源于stack exchange,提问作者Adam Boostani

