| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
Topics
Suppose you want to host your static website on Amazon S3. You have registered a domain,
for example, example.com, and you want requests for
http://www.example.com and http://example.com to be served
from your Amazon S3 content.
Whether you have an existing static website that you now want to host on Amazon S3 or you are starting from scratch, this example will help you host websites on Amazon S3.
As you walk through the steps in this example, note that you will work with the following services:
Domain registrar of your choice– If you do not already
have a registered domain name, such as example.com, you will need to create
and register one with a registrar of your choice. You can typically register a domain
for a small yearly fee. For procedural information about registering a domain name, see
the web site of the registrar
Amazon S3– You will use Amazon S3 to create buckets,
upload a sample website page, configure permissions so everyone can see the content, and
then configure the buckets for website hosting. In this example, because you want to
allow requests for both http://www.example.com and
http://example.com, you will create two buckets; however, you will host
content in only one bucket. You will configure the other Amazon S3 bucket to redirect
requests to the bucket that hosts the content.
Amazon Route 53– You will configure Amazon Route 53 as your DNS provider. You will create a hosted zone in Amazon Route 53 for your domain and configure applicable DNS records. If you are switching from an existing DNS provider, you will need to ensure that you have transferred all of the DNS records for your domain.
As you walk through this example, a basic familiarity with domains, Domain Name System (DNS), CNAME records, and A records would be helpful. A detailed explanation of these concepts is beyond the scope of this guide, but your domain registrar should provide any basic information that you need.
Note
All the steps in this example use example.com as a
domain name. You will need to replace this domain name with the one you
registered.
If you already have a registered domain, you can skip this step. If you are new to
hosting a website, your first step is to register a domain, such as
example.com, with a registrar of your choice.
After you have chosen a registrar, you will register your domain name according to the instructions at the registrar’s website. For a list of registrar web sites that you can use to register your domain name, go to ICANN.org.
When you have a registered domain name, your next task is to create and configure Amazon S3 buckets for website hosting and to upload your website content.
In this example, to support requests from both the root domain such as
example.com and subdomain such as www.example.com, you
will create two buckets. One bucket will contain the content and you will configure the
other bucket to redirect requests. You perform the following tasks in Amazon S3 console
to create and configure your website:
Create two buckets.
Configure these buckets for website hosting.
Test the Amazon S3 provided bucket website endpoint.
The bucket names must match the names of the website that you are hosting. For example, to
host your example.com website on Amazon S3, you would create a bucket
named example.com. To host a website under
www.example.com, you would name the bucket
www.example.com. In this example, your website will support requests
from both example.com and www.example.com.
In this step, you will sign in to the Amazon S3 console with your AWS account credentials and create the following two buckets.
example.com
www.
example.com
Note
To create the buckets for this example, follow these steps. As you walk through this
example, substitute the domain name that you registered for
example.com.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.
Create two buckets that match your domain name. One of the bucket names should include the
subdomain www, For instance,
and
example.comwww..example.com
For step-by-step instructions, go to Creating a Bucket in the Amazon Simple Storage Service Console User Guide.
Upload your website data to the
bucket. example.com
You will host your content out of the root domain bucket
(), and you will
redirect requests for
example.comwww. to the root
domain bucket. Note that you can store content in either bucket. For this
example you will host content in
example.com bucket. The
content can be text files, family photos, videos—whatever you want. If you
have not yet created a website, then you only need one file for this
example. You can upload any file. For example, you can create a file using
the following HTML and upload it the bucket. The file name of the home page
of a website is typically index.html, but you can give it any name. In a
later step, you will provide this file name as the index document name for
your website.example.com
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>My Website Home Page</title>
</head>
<body>
<h1>Welcome to my website</h1>
<p>Now hosted on Amazon S3!</p>
</body>
</html>
For step-by-step instructions, go to Uploading Objects into Amazon S3 in the Amazon Simple Storage Service Console User Guide.
Configure permissions for your objects to make them publicly accessible.
Attach the following bucket policy to the
bucket substituting
the name of your bucket for example.comexample.com. For
step-by-step instructions to attach a bucket policy, go to Editing Bucket Permissions in the Amazon Simple
Storage Service Console User Guide.
{
"Version":"2008-10-17",
"Statement":[{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::example.com/*"
]
}
]
}
You now have two buckets, example.com and
www.example.com, and you have uploaded your
website content to the example.com bucket. In the
next step, you will configure www.example.com to
redirect requests to your example.com bucket. By
redirecting requests you can maintain only one copy of your website content
and both visitors who specify “www” in their browsers and visitors that only
specify the root domain will both be routed to the same website content in
your example.com bucket.
When you configure a bucket for website hosting, you can access the website using the Amazon S3 assigned bucket website endpoint.
In this step, you will configure both buckets for website hosting. First, you will configure
as a website and then
you'll configure example.comwww. to redirect
all requests to the example.com
bucket.example.com
To configure bucket for website
hostingexample.com
Configure bucket for website hosting.
In the Index Document box, type the name
that you gave your index page. example.com
For step-by-step-instructions, go to Managing Bucket Website Configuration in the Amazon Simple Storage Service Console User Guide. Make a note of the URL for the website endpoint. You will need it later.

To test the website, enter the Endpoint URL in your browser.
Your browser will display the index document page. Next, you will configure
www. bucket to
redirect all requests for
example.comwww. to
example.com.example.com
To redirect requests from www. to
example.comexample.com
In the Amazon S3 console, in the Buckets list, right-click
www. and then
click Properties.example.com
Under Static Website Hosting, click Redirect all requests
to another host name. In the Redirect all
requests box, type
example.com.

To test the website, enter the Endpoint URL in your browser.
Your request will be redirected and the browser will display the index document for
example.com.
The following Amazon S3 bucket website endpoints are accessible to any internet user:
http://example.com.s3-website-us-east-1.amazonaws.com
http://www.example.com.s3-website-us-east-1.amazonaws.com
Now you will do additional configuration to serve requests from the domain you registered in the preceding step. For example, if you registered a domain example.com, you want to serve requests from the following URLs :
http://example.com
http://www.example.com
In the next step, we will use Amazon Route 53 to enable customers to use the URLs above to navigate to your site.
Now you will configure Amazon Route 53 as your Domain Name System (DNS) provider. You must
use Amazon Route 53 if you want to serve content from your root domain, such as
. You will create a hosted
zone, which holds the DNS records associated with your domain:example.com
Alias record– Maps the domain to the
Amazon S3 website endpoint (for example,
s3-website-us-east-1.amazonaws.com).example.com
CNAME record– Maps the domain www. to
the corresponding Amazon S3 bucket website endpoint. Any requests to
example.comhttp://www. will
be routed to the Amazon S3 bucket website endpoint.example.com
Go to the Amazon Route 53 console at https://console.aws.amazon.com/route53 and then create a hosted zone for your domain. For step-by-step instructions, go to Creating a Hosted Zone in the Amazon Route 53 Developer Guide.
The following example shows the hosted zone created for the example.com
domain. Write down the Route 53 name servers (NS) for this domain. You will need
them later.

The alias record that you add to the hosted zone for your domain will map
to the corresponding
Amazon S3 bucket. Instead of using an IP address, the alias record uses the Amazon
S3 website endpoint. Amazon Route 53 maintains a mapping between the alias record
and the IP address where the Amazon S3 bucket resides. example.com
For step-by-step instructions, go to Creating an Alias Resource Record Set in the Amazon Route 53 Developer Guide.

To enable this hosted zone, you must use Amazon Route 53 as the DNS server for your domain
example.com.
Before you switch, if you are moving an existing website to Amazon S3, you must
transfer DNS records associated with your domain example.com to the hosted zone that
you created in Amazon Route 53 for your domain. If you are creating a new website,
you can go directly to step 4.
The CNAME record that you add routes requests for
www. to the endpoint for
the corresponding Amazon S3 bucket. For step-by-step instructions, go to Creating, Changing, and Deleting Resource Record Sets in the
Amazon Route 53 Developer Guide. The CNAME value shown in the following
example is the host name that you specified in the Amazon S3 console.example.com

Before you switch to Amazon Route 53 as your DNS provider, you must transfer any remaining DNS records from your current DNS provider, including MX records, CNAME records, and A records, to Amazon Route 53. You don't need to transfer the following records:
NS records– Instead of transferring these, you replace their values with the name server values that are provided by Amazon Route 53.
SOA record– Amazon Route 53 provides this record in the hosted zone with a default value.
Migrating required DNS records is a critical step to ensure the continued availability of all the existing services hosted under the domain name.
To switch to Amazon Route 53 as your DNS provider, you must go to your current DNS provider and update the name server (NS) record to use the name servers in your delegation set in Amazon Route 53.
Go to your DNS provider site and update the NS record with the delegation set values of the hosted zone as shown in the following Amazon Route 53 console screenshot. For more information, go to Updating Your DNS Service's Name Server Records in Amazon Route 53 Developer Guide.

When the transfer to Route 53 is complete, there are tools that you can use to verify the
name server for your domain has indeed changed. On a Linux computer, you can use the
dig DNS lookup utility. For example, this dig
command:
dig +recurse +trace www.example.com any
returns the following output (only partial output is shown). The output shows the same
four name servers the name servers on Amazon Route 53 hosted zone you created for
example.com domain.
... example.com. 172800 IN NS ns-9999.awsdns-99.com. example.com. 172800 IN NS ns-9999.awsdns-99.org. example.com. 172800 IN NS ns-9999.awsdns-99.co.uk. example.com. 172800 IN NS ns-9999.awsdns-99.net. www.example.com. 300 IN CNAME www.example.com.s3-website-us-east-1.amazonaws.com. ...
To verify that the website is working correctly, in your browser, try the following URLs:
http:// - Displays the index document
in the example.com bucket.example.com
http://www.- Redirects your request to
example.comhttp://. example.com