How do I create alias resource record sets in Amazon Route 53 using the AWS Command Line Interface (AWS CLI)?

You can use an alias record in Route 53 to point to an AWS resource or an Amazon S3 bucket. You can create an alias record through the Route 53 console or through the AWS CLI.

Note: Be sure that you install or upgrade to the latest version of the AWS CLI before you proceed.

Before you create alias resource record sets, create a hosted zone to contain the records for routing traffic to your domain. The hosted zone and your domain must have the same name. Depending on your use case, you can create either a public hosted zone for routing Internet traffic or a private hosted zone for routing traffic within an Amazon Virtual Private Cloud (Amazon VPC).

Create your alias resource record set

Modify the following sample JSON syntax to create your own alias resource record set, and then specify your own values for the alias records. Save the file (for example, sample.json).

Warning: Be sure that you use the hosted zone ID of your AWS resources, and not your domain name, in your configuration. In the JSON file, this value is specified in the key-value pair HostedZoneId. Before you proceed, locate the HostedZoneId for Elastic Load Balancing, AWS Elastic Beanstalk, Amazon Simple Storage Service (Amazon S3), and Amazon CloudFront endpoints for each region.

This example creates the alias resource record set for a domain (elb.example.com) to point to an Elastic Load Balancer endpoint (ALB-xxxxxxxx.us-west-2.elb.amazonaws.com). The request body includes a list of change items, known as a change batch. Change items are included with a ChangeResourceRecordSetsRequest element.

{
     "Comment": "Creating Alias resource record sets in Route 53",
     "Changes": [{
                "Action": "CREATE",
                "ResourceRecordSet": {
                            "Name": "elb.example.com",
                            "Type": "A",
                            "AliasTarget":{
                                    "HostedZoneId": "Z1H1FL5HABSF5",
                                    "DNSName": "ALB-xxxxxxxx.us-west-2.elb.amazonaws.com",
                                    "EvaluateTargetHealth": false
                              }}
                          }]
}

Next, use a change-resource-record-sets command to create your resource record set in a hosted zone. The values for record creation are specified in the JSON configuration file that you created previously.

Modify the following command for your configuration. For the --hosted-zone-id, provide your hosted zone ID for the domain name:

$ aws route53 change-resource-record-sets --hosted-zone-id ZXXXXXXXXXX --change-batch file://sample.json

Elastic Load Balancing settings

If you're pointing to an Elastic Load Balancer, always include dualstack in the value for the DNSName key-value pair of the JSON file. For example, if your load balancer's Amazon-provided DNS name is ALB-xxxxxxxx.us-west-2.elb.amazonaws.com, use:

"DNSName": "dualstack.ALB-xxxxxxxx.us-west-2.elb.amazonaws.com"

CloudFront distribution settings

If you're pointing to a CloudFront distribution, specify the Amazon-provided CloudFront distribution domain name in the DNSName key-value pair of the JSON file. For example, if your CloudFront distribution Amazon-provided domain name is d111111abcdef8.cloudfront.net, use:

"DNSName": "d111111abcdef8.cloudfront.net"

Warning: You must include an alternate domain name to use instead of the CloudFront-assigned one. The alternate domain name must match the domain for which you created the alias resource record set. For example, if you want to access your CloudFront distribution using the domain example.com, add the domain name to the Alternate Domain Names for the distribution.

Amazon S3 bucket settings

If you're pointing to an Amazon S3 bucket, you must 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 S3 management console for the value. The domain name for which you create the resource record set must match the name of your Amazon S3 bucket.

You must also specify the region where the bucket is hosted (for example, us-east-1).

s3-website-us-east-1.amazonaws.com

The following is example JSON syntax for pointing to an S3 bucket:

{
                "Comment": "Alias record for S3 bucket",
     "Changes": [{
                "Action": "CREATE",
                "ResourceRecordSet": {
                                "Name": "new.example.com",
                                           "Type": "A",
                                "AliasTarget":{
                                                    "HostedZoneId": "Z3BJ6K6RIION7M",
                                          "DNSName": "s3-website-us-west-2.amazonaws.com",
                                               "EvaluateTargetHealth": false
                                         }}
                                  }]
}

Note: In addition to creating Alias record pointing to the AWS resources such as CloudFront distribution, Elastic Beanstalk environment, ELB load balancer, Amazon S3 bucket, you can also create an Alias resource record that points to another record set in the same hosted zone that you're creating the alias record in. The alias record must have the same type as the record you're routing to.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-08-09