Getting Started with AWS
Hosting a Static Website
« 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...

Step 5: Associate a Domain Name with Your Website Using Amazon Route 53 (Optional)

This step is associates a memorable domain name with your Amazon S3 bucket. It is optional. If you want to associate a domain name with your website and you skipped Step 2: Choose a Domain Name, go back and do that step now. If you performed step 2, you must have used your domain name in place of example.com throughout this guide.

Amazon Route 53 is the service we'll use to associate your custom domain name with your static website. Amazon Route 53 is a scalable Domain Name System (DNS) service that provides secure and reliable routing to locations both inside and outside of AWS.

With Amazon Route 53, you pay only for the domains you configure and the number of queries that the service answers. The Amazon Route 53 charges that you will incur for following this guide are minimal, approximately $0.50 a month. For information about Amazon Route 53 pricing, see Amazon Route53 Cost Breakdown.

In this step you will do the following:

  • Allocate name servers on Amazon Route 53 to route traffic for your custom domain

  • Configure routing records for your root domain and www subdomain

  • Set up Amazon Route 53 as your DNS provider

In this step, you'll associate an A record with the root domain and the www subdomain. The following diagram shows how Amazon Route 53 routes the root domain and www subdomain traffic after this step is completed.

To allocate name servers on Amazon Route 53

  1. Open the Amazon Route 53 console at https://console.aws.amazon.com/route53/.

  2. In the Route 53: Hosted Zones window, click Create Hosted Zone.

  3. In the Domain Name box, type your custom domain name.

  4. Click the Create Hosted Zone button at the bottom of the pane.

  5. When the hosted zone is successfully created, in the list of domain names, select the check box that corresponds to your domain name. In the details pane, under Delegation Set, Amazon Route 53 displays the set of name servers that have been allocated for your domain. You’ll be needing the names of these name servers later on.

To configure the A record for your root domain

  1. In the Amazon Route 53 console, in the details pane, select the check box that corresponds to your domain name.

  2. Click Go to Record Sets.

  3. Click Create Record Set.

  4. Under Create Record Set, do the following:

    • In the Name box, accept the default. The root domain is already entered for you.

    • In the Type box, select A — IPv4 address to create an A record for your domain.

    • In Alias, click Yes. This option causes the A record you create to point to an AWS resource—in this case, an Amazon S3 bucket—instead of an IP address. An alias makes it possible to associate your custom domain with the website you have hosted in Amazon S3. Normally, an A record can be associated only with a numerical IP address (such as 192.0.2.255). When you create the A record as an alias, AWS maps the A record to your Amazon S3 endpoint. Amazon Route 53 is the only DNS provider that can map the A record of a domain to an S3 bucket.

    • Click Alias Target. Select your root domain website endpoint (example.com) from the dropdown list that appears. You created this endpoint in Step 4: Launch Your Website on Amazon S3. Take care not to select the www subdomain endpoint instead (www.example.com).

    • In the Routing Policy box, select Simple.

    • Leave Evaluate Target Health set to No.

  5. Click the Create Record Set button at the bottom of the pane.

Next, you'll create an A record that points to the www subdomain. Amazon Route 53 does not charge for queries made against aliases. If you create A records pointing to aliases for both the root domain and the www subdomain the only Amazon Route 53 charge is for the domain hosting. If you had used a CNAME instead of an A record for the www subdomain, you would also be charged for queries on that CNAME. By using an A record, you also save your site's visitors a second DNS lookup to resolve the CNAME.

To configure the A record for your www subdomain

  1. In the Amazon Route 53 console, in the details pane, select the check box that corresponds to your domain name.

  2. Click Go to Record Sets.

  3. Click Create Record Set.

  4. Under Create Record Set, do the following:

    • In the Name box, type www. The root domain is already entered for you, and the connecting period (.) is entered for you when you start typing.

    • In the Type box, select A — IPv4 address to create an A record for your domain.

    • In Alias, click Yes.

    • In the Alias Target box, click your www subdomain website endpoint (www.example.com) from the dropdown list that appears. You created this endpoint in Step 4: Launch Your Website on Amazon S3. Take care not to select the root domain endpoint instead (example.com).

    • In the Routing Policy box, click Simple.

    • Leave Evaluate Target Health set to No.

  5. Click the Create Record Set button at the bottom of the pane.

If you registered a new domain name in Step 2: Choose a Domain Name and have used that name during this guide, you're ready to set up Amazon Route 53 as your DNS provider. If you're reusing a domain name that was previously associated with another website, you may need to transfer other DNS records from your current DNS provider to Amazon Route 53 in order to ensure the continued availability of the services hosted under the domain name. For example, Mail Exchange (MX) records specify routing for email associated with the domain. If you do not replicate your MX records in Amazon Route 53 before you make Amazon Route 53 your DNS provider, your email will not be properly routed. To determine what DNS records you need to replicate in Amazon Route 53, check the DNS record settings configured for the domain in your current DNS provider. Two records that you should not transfer to Amazon Route 53 are the Start of Authority (SOA) and Name Server (NS) records. These records were set by Amazon Route 53 when the name servers were allocated, and they should not be changed.

To set up Amazon Route 53 as your DNS service provider

  1. In the Amazon Route 53 console, in the details pane, select the check box that corresponds to your domain name.

  2. Make a note of the values in Delegation Set.

  3. Log into the domain name registrar that you used to register your domain name in Step 2: Choose a Domain Name. Use the registrar’s web interface to change the name servers for your domain to the name server values you noted in the previous step. How you do this depends on the registrar that you used. For the specific procedure, see their online help. Below is an example of updating the name servers on a domain provider's website.

    Some registrars allow you to specify name servers only by using IP addresses; they don't allow you to specify fully qualified domain names. If your registrar requires using IP addresses, you can get the IP addresses for your name servers by using a command line utility such as dig (for Mac OS X, Unix, or Linux) or nslookup (for Windows). The following example shows how to locate the IP address associated with the domain name of the name server ns-330.awsdns-41.com using dig.

    dig ns-105.awsdns-13.com

    The value you would use to set the name server if you have to use an IP address instead of a domain name is the IP address that is returned under ANSWER SECTION in the dig output. You should use the IP address only if it is required by your domain registrar. The preferred method of setting the name servers is by using the domain name. Using the domain name protects you if the IP address associated with a allocated name server ever changes.

    ;; ANSWER SECTION:
    ns-105.awsdns-13.com.	172800	IN	A	203.0.113.0
    			
  4. Wait for 2 to 48 hours. This is the time it takes the Internet DNS resolver network to propagate name server changes. To see if the name server change has gone, use a command line utility such as dig (for Mac OS X, Unix, or Linux) or nslookup (for Windows). The following example shows how use dig to see which name servers are associated with your domain.

    dig example.com

    When the AUTHORITY SECTION of the output shows the AWS name servers that you allocated using Amazon Route 53, the DNS changes have propagated through the DNS resolver network.

    ;; AUTHORITY SECTION:
    example.com.	118928	IN	NS	ns-806.awsdns-36.net.
    example.com.	118928	IN	NS	ns-1456.awsdns-54.org.
    example.com.	118928	IN	NS	ns-1713.awsdns-22.co.uk.
    example.com.	118928	IN	NS	ns-105.awsdns-13.com.
    			

    If you don't want to use a command line utility to determine when the new name server values have taken effect, you can try to go to http://example.com in a web browser every so often. When you see your "Hello World" web page, you know the DNS changes have propagated out.

    After your DNS changes have propagated, you'll be able to view your website using your custom domain name.

    If you open www.example.com in your web browser, it will redirect to example.com.

Where You're At

Congratulations! You've successfully associated a custom domain with your website hosted on Amazon S3.

If your website has few visitors, does not include large files, and most users are in the same geographical area as your root domain bucket, you probably don't need a CloudFront distribution network yet. You can add a CloudFront distribution to your site later, when traffic increases.

In Step 6: Speed Up Your Website Using CloudFront (Optional), we'll use Amazon CloudFront to create a content delivery network (CDN) that will improve the speed of your website. CloudFront sends visitors to edge locations, automatically updating the content cached at that location if a new version is available. The improvement in performance is especially notable if you are delivering large files, such as high resolution images, audio, or video.