I want to use the AWS Command Line Interface (AWS CLI) to create alias resource record sets in Amazon Route 53.
Resolution
Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
Before you create alias resource record sets, create a hosted zone that contains the records about how to route traffic for your domain. The hosted zone and your domain must have the same name. You can either create a public hosted zone. Or, you can create a private hosted zone for records about how to route traffic within an Amazon Virtual Private Cloud (Amazon VPC).
Create your alias resource record set
Complete the following steps:
-
Modify the following sample JSON syntax to create the alias resource record set. Specify values for the alias records.
Important: Make sure that you use the hosted zone ID of your AWS resources and not your domain name. In the JSON file, this value is specified in the HostedZoneId key-value pair. Find the Hosted Zone ID for Elastic Load Balancing (ELB), AWS Elastic Beanstalk, Amazon Simple Storage Service (Amazon S3), and Amazon CloudFront endpoints for each AWS Region.
The following example creates the alias resource record set for the elb.example.com domain to point to the ALB-########.us-west-2.elb.amazonaws.com load balancer endpoint. The request body includes a list of change items. Change items are included with the ChangeResourceRecordSetsRequest element:
{ "Comment": "Creating Alias resource record sets in Route 53",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "elb.example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z############",
"DNSName": "ALB-########.us-west-2.elb.amazonaws.com",
"EvaluateTargetHealth": false
}
}
}
]
}
-
Save the file.
-
Run the change-resource-record-sets command to create your resource record set in a hosted zone:
$ aws route53 change-resource-record-sets --hosted-zone-id Z########## --change-batch file://sample.json
Note: Replace hosted-zone-id with your hosted zone ID and sample.json with your file's name.
Elastic Load Balancing settings
If you point to a load balancer, then always include dualstack in the Amazon provided DNS name value for the DNSName key-value pair of the JSON file.
Example:
"DNSName": "dualstack.ALB-abcdefgh.us-west-2.elb.amazonaws.com"
CloudFront distribution settings
If you point to a CloudFront distribution, then specify the Amazon provided CloudFront distribution domain name in the DNSName key-value pair of the JSON file.
Example:
"DNSName": "d111111abcdef8.cloudfront.net"
Important: You must include an alternate domain name to use instead of the CloudFront assigned domain name. The alternate domain name must match the name of the domain that you created the alias resource record set for. For example, to access your CloudFront distribution through the domain example.com, add the domain to the alternate domain names for the distribution.
Amazon S3 bucket settings
If you point to an S3 bucket, then specify the domain name of the bucket's website endpoint for the DNSName key-value pair in the JSON file. Don't use the S3 endpoint that appears in the static website hosting from your Amazon S3 console. The name of your Amazon S3 bucket must match the name of the domain that you created the alias resource record set for.
You must also specify the Region where the bucket is hosted.
Example:
s3-website-us-east-1.amazonaws.com
The following is example JSON syntax that points to an S3 bucket:
{ "Comment": "Alias record for S3 bucket",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "new.example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z############",
"DNSName": "s3-website-us-west-2.amazonaws.com",
"EvaluateTargetHealth": false
}
}
}
]
}
Note: You can also create an alias resource record that points to another record in the same hosted zone that you create the alias record in. The alias record must have the same type as the record that you route to.
Related information
How do I troubleshoot errors that I received while creating Route 53 resource record sets using the AWS CLI?