Elastic Load Balancing
Developer Guide (API Version 2012-06-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Configure Custom Domain Name for Your Load Balancer

Each Elastic Load Balancing instance that you create has an automatically created Domain Name System (DNS) name. Typically, the DNS name includes the name of the AWS region in which the load balancer is created. For example, if you create a load balancer named myLB in the US-East region, your load balancer might have a DNS name such as myLB-1234567890.us-east-1.elb.amazonaws.com. You just have to paste the DNS name generated by Elastic Load Balancing into the address field of an Internet-connected web browser to connect to your load balancer.

If you'd rather use a user-friendly domain name, such as www.example.com, instead of the load balancer DNS name, you can create a custom domain name and then associate the custom domain name with the load balancer DNS name. When a request is placed to your load balancer using the custom domain name that you created, it resolves to the load balancer DNS name.

To use a custom domain name for your load balancer instance, you’ll have to first register your domain name with a DNS service provider.

When you register a domain name, you reserve not only the domain name itself, but also an entire set of subdomain names. For example, if you register example.com as your custom domain name, you can create subdomain names such as foo.bar.example.com, foo.myLB.example.com, and so on. This set of a domain and its subdomain names is called a zone. A domain name that you reserve, such as example.com, is called the zone apex because it sits at the top of the zone's hierarchy.

Associating Your Custom Domain Name with Your Load Balancer Name

After you register your custom domain name, you have two ways to associate your custom domain name with the load balancer DNS name.

  • Option 1: Create a canonical name (CNAME) record for your zone with your existing domain name provider.

    To associate your custom domain name with your load balancer, first create a canonical name (CNAME) record for your zone with your existing domain name provider.

    A CNAME record specifies that a domain name is an alias of another CNAME domain name. For example, the following CNAME record associates an alias, www.foo.example.com, with a canonical name, the DNS name of an Elastic Load Balancing instance.

    www.foo.example.com CNAME myLB-1234567890.us-east-1.elb.amazonaws.com 

    For more information on CNAME records, go to the Wikipedia article http://en.wikipedia.org/wiki/CNAME_record.

    The creation of CNAME records is a simple process. Many domain name registrars provide self-service tools that you can use to create the CNAME record yourself. However, you can't use a CNAME record to associate your zone apex with your Elastic Load Balancing instance. DNS rules prohibit the creation of a CNAME record at the zone apex (e.g., example.com). For example, if you own the example.com domain name, you can use a CNAME record for the foo.example.com subdomain name, but not for the example.com zone apex.

    You can use the next option if you want to associate a zone apex with your load balancer DNS name.

  • Option 2: Create a domain using Amazon Route 53 as the DNS service Amazon Route 53 stores information about your domain in a hosted zone. A hosted zone is an Amazon Route 53 concept that is similar to a zone file on a DNS name server. Like a zone file, a hosted zone contains information about your domain name, including the subdomain names within the domain and mappings between names and IP addresses. For more information about Amazon Route 53, go to What is Route 53 and How Does it Work?

    Use this option to associate a zone apex with your load balancer DNS name. You’ll use Amazon Route 53 to create a hosted zone for your domain (for example, example.com), and then create alias resource record sets. An alias resource record set contains a pointer to a resource record set that contains your DNS resource records. For example, an alias resource record set for your domain, example.com, can point to the DNS name of your Elastic Load Balancing load balancer instance myLB-1234567890.us-east-1.elb.amazonaws.com. After you create a hosted zone, you can also create alias resource record sets to associate subdomain names with your Elastic Load Balancing instance.

    DNS Failover: When you use Route 53 to create and associate a custom domain name with your load balancer you have an option to enable DNS failover for your load balancer. If DNS failover is enabled, Route 53 responds to the queries to your alias record set, example.com based on the health checks of the associated primary and secondary load balancer instances.

    If you plan to enable DNS failover for your load balancers, see Configure DNS Failover for Your Load Balancer.

This section describes how to associate your Elastic Load Balancing instance with a custom domain name using Option 1 or Option 2.

Prerequisite

Before you start associating a load balancer DNS name with a custom domain name, you first need to create a load balancer. For information on creating a basic load balancer, see Get Started with Elastic Load Balancing For information on creating a load balancer with custom settings, see Create a HTTPS/SSL Load Balancer .

Note

The time-to-live (TTL) for an Elastic Load Balancing DNS entry is set to 60 seconds. This setting ensures that IP addresses can be re-mapped quickly to respond to events that cause Elastic Load Balancing to scale up or down.

Option 1: Create a CNAME Record for your subdomain and load balancer

  1. Register your custom domain name with your DNS provider. For a list of registrar websites you can use to register your domain name, go to ICANN. Wait for your registrar to notify you that your domain name is successfully registered.

  2. Create a subdomain name to associate with your load balancer DNS name. For example, if your custom domain name is example.com, you can create a subdomain name such as foo.mylb.example.com.

  3. Retrieve the public DNS name of your load balancer. You can use AWS Management Console, the Elastic Load Balancing Query API, or the Elastic Load Balancing command line interface (CLI) to retrieve your load balancer DNS name.

    To use the AWS Management Console to retrieve the public DNS name of your load balancer

    1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

    2. On the Amazon EC2 console Resources page, in the EC2 Dashboard pane, under NETWORK & SECURITY, click Load Balancers.

    3. On the Load Balancers page, select your load balancer.

    4. The bottom pane displays the details of your load balancer.

    5. Make a note of the DNS name of your load balancer.

  4. To use the Elastic Load Balancing Query API to retrieve the public DNS name of your load balancer

    1. Call DescribeLoadBalancers with the following parameter:

      LoadBalancerName = your load balancer name

      The operation returns the DNS name of your load balancer along with other details.

    2. Make a note of the DNS name.

  5. To use the Elastic Load Balancing CLI to retrieve the public DNS name of your load balancer

    1. You'll need to install the Elastic Load Balancing CLI tool before you can use the following command. If you haven't yet installed the tool, go to Install the Elastic Load Balancing Command Line Interface for instructions on downloading and installing the CLI tool.

    2. Enter the command elb-describe-lbs, as in the following example.

      PROMPT> elb-describe-lbs your load balancer name

      The command returns the DNS name of your load balancer along with other details.

    3. Make a note of the DNS name.

  6. Create a CNAME record to associate your custom subdomain name with your load balancer DNS name, as in the following example:

    Note

    Ask the company that provides your DNS name services (your domain name registrar) to create a CNAME record for your zone. Many domain name registrars provide self-service tools that you can use to create the CNAME record yourself.

    www.foo.mylb.example.com CNAME myLB-1234567890.us-east-1.elb.amazonaws.com 

Option 2: Create an Amazon Route 53 hosted zone

  1. Register your custom domain name with your DNS provider. For a list of registrar websites you can use to register your domain name, go to ICANN. Wait for your registrar to notify you that your domain name is successfully registered.

  2. Create a hosted zone for your custom domain name using Amazon Route 53. For detailed instructions, go to Creating a Hosted Zone in Amazon Route 53 Developer Guide.

    As with other AWS products, there are no contracts or minimum commitments for using Amazon Route 53—you pay only for the hosted zones that you configure and the number of queries that Route 53 answers. For more information, see Route 53 Pricing.

  3. For each hosted zone you create, Route 53 automatically creates four name server (NS) records. These four name servers are called the delegation set. Before the Domain Name System will start to route queries for your domain to Route 53 name servers, you must update your registrar's or your DNS service's name server records, to point to the Route 53 name servers.

    Follow the instructions in Getting the Name Servers for a Hosted Zone to get the four name servers assigned to your hosted zone.

    Follow the instructions in Name Server (NS) Records to update your registrar's or your DNS service's name server records, to point to the Route 53 assigned name servers.

  4. Create an alias resource record set you will use to associate your zone apex with your Elastic Load Balancing instance DNS name. To create the alias resource record set you can use the Amazon Route 53 console, Amazon Route 53 API, or the Elastic Load Balancing command line interface (CLI).

    To use Amazon Route 53 console or Amazon Route 53 Query API

    For detailed instructions on using the Amazon Route 53 console or the Amazon Route 53 Query API to create an alias resource record set, go to Creating Alias Resource Record Sets in the Amazon Route 53 Developer Guide.

    To use the Elastic Load Balancing command line interface

    1. Before you get started, be sure you’ve installed the Elastic Load Balancing CLI tools. For more information, see Install the Elastic Load Balancing Command Line Interface for instructions on downloading and installing the CLI tools. For detailed descriptions of the Elastic Load Balancing commands, see the Elastic Load Balancing Quick Reference Card.

    2. Enter the elb-associate-route53-hosted-zone command, as in the following example, to associate a zone apex with an Elastic Load Balancing instance.

      This command creates an association between your zone apex and your Elastic Load Balancing instance by adding an alias resource record set to your hosted zone. The following example creates an association between example.com and a load balancer named myLoadBalancer.

      elb-associate-route53-hosted-zone myLoadBalancer --rr-name example.com --hosted-zone-id Z123456789 --weight 100 

      For the hosted-zone-id parameter, use the hosted zone ID of your custom domain name rather than the Elastic Load Balancing hosted zone ID. For instructions on getting the hosted zone ID of your custom domain name, go to Listing the Hosted Zones for an AWS Account.

      For more information about the weight parameter, go to Setting Up Weighted Resource Record Sets in the Amazon Route 53 API Reference Guide.

      Note

      You might have to wait several minutes for your changes to propagate to all Amazon Route 53 DNS servers. For information on how to check the status of your change, go to Checking the Status of Your Change in the Amazon Route 53 Developer Guide.

    3. You can also use elb-associate-route53-hosted-zone to create aliases for subdomains that are part of your hosted zone. The following example associates the subdomain foo.bar.example.com your Amazon Route 53 hosted zone with ID number Z123456789.

      elb-associate-route53-hosted-zone myLoadBalancer --rr-name foo.bar.example.com --hosted-zone-id Z123456789 --weight 100

      Note

      The elb-associate-route53-hosted-zone command works only with AWS secret key authentication. Unlike other Elastic Load Balancing CLI commands, this Elastic Load Balancing command does not work with X.509 certificate and RSA private key credentials.

Disassociating Your Custom Domain Name From Your Load Balancer Name

You can disassociate your custom domain name from a load balancer instance by first deleting the resource record sets in your hosted zone and then deleting the hosted zone.

  1. Delete the alias resource record sets in your Amazon Route 53 hosted zone

    You can use Amazon Route 53 console, Amazon Route 53 API, or the Elastic Load Balancing command line interface (CLI) to delete alias resource record sets in your hosted zone.

    Using the Amazon Route 53 Console

    Using the Amazon Route 53 Query API

    Using the Elastic Load Balancing command line interface

    • Enter the elb-disassociate-route53-hosted-zone command.

      This command removes the association between your zone apex or subdomain and your Elastic Load Balancing instance by deleting an alias resource record set from your hosted zone. The following example removes an association between example.com and a load balancer named myLB. The hosted-zone-id parameter is your custom hosted zone ID.

      elb-disassociate-route53-hosted-zone myLB --rr-name example.com --hosted-zone-id Z123456789 --weight 100

    Note

    The weight parameter value must match the value you used to create the resource record set specified in the rr-name parameter. If you don't remember the original weight value, use the Amazon Route 53 ListResourceRecordSets action to retrieve the value. For more information, go to ListResourceRecordSets in the Amazon Route 53 API Reference Guide. For more information about the weight parameter, go to Setting Up Weighted Resource Record Sets in the Amazon Route 53 API Reference Guide.

    Note

    The elb-disassociate-route53-hosted-zone command works only with AWS secret key authentication. Unlike other Elastic Load Balancing CLI commands, this new Elastic Load Balancing command does not work with X.509 certificate and RSA private key credentials.

  2. Delete the hosted zone associated with your load balancer DNS name

    You can use the Amazon Route 53 console or the Amazon Route 53 Query API to delete the hosted zone associated with your load balancer DNS name. For more information, go to Deleting a Hosted Zone in the Amazon Route 53 Developer Guide.