Menu
Getting Started with AWS
Hosting a Static Website

Step 3: Deploy Your Website

Now that you've created and configured your Amazon S3 buckets, you are ready to deploy your website. If you don't already have files for a website, you can just use the simple HTML files we create in this step.

To deploy your static website, use Amazon S3 to complete the following tasks.

Create an Index Document and a Custom Error Document

An index document is the default page of a website. A custom error document is a document in which Amazon S3 returns HTTP 4.x error codes, if you configure your website to use this type of document. Create an index document with the name index.html, and create a custom error document with the name error.html. Save these documents on your computer where you can easily find them.

Add the following HTML to index.html:

Copy
<!DOCTYPE html> <html> <body> <p>Hello, World!</p> </body> </html>

Add the following HTML to error.html:

Copy
<!DOCTYPE html> <html> <body> <p>This is an error page.</p> </body> </html>

For more information on index documents and custom error documents, go to Index Document Support and Custom Error Document Support in the Amazon Simple Storage Service Developer Guide.

Upload Files to Your Bucket

To upload your website files to your root domain Amazon S3 bucket

If you already have the Amazon S3 console open, skip step 1.

  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Select your root domain bucket.

  3. Choose Actions, and then choose Upload.

  4. In the Upload — Select Files dialog box, do the following:

    1. Choose Add Files.

    2. In the File Upload dialog box, select the index.html and error.html files that you created, and then choose Open.

    3. Choose Start Upload.

  5. When your files have finished uploading, they appear as follows.

  6. (Optional) Upload any other files for your website.

    If your website files have a folder hierarchy on your local computer, such as storing image files in an images subfolder, you need to recreate that hierarchy in your buckets. To do so, simply create folders inside the root domain bucket that match your folder hierarchy. For example, consider the case where you have a file /images/check.gif referenced in index.html as follows.

    Copy
    <!DOCTYPE html> <html> <body> <p>Hello, World!</p> <img src="/images/check.gif"> </body> </html>

    To create this folder, open your root domain bucket, choose Create Folder, create the images folder, and then upload check.gif to the new images folder.

Configure Your Bucket as a Website

After you configure your bucket as a website, Amazon S3 can serve the files in the bucket as if they were hosted on a web server.

To configure your root domain bucket as a website

If you already have the Amazon S3 console open, skip step 1.

  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the Buckets pane, choose your root domain bucket, choose Properties, and then choose Static Website Hosting.

  3. Make a note of the value of Endpoint, for example example.com.s3-website-us-east-1.amazonaws.com. You'll need this value if you decide to set up a CDN.

  4. Complete the Static Website Hosting pane as follows:

    1. Choose Enable website hosting.

    2. For Index Document, type index.html.

    3. For Error Document, type error.html.

    4. Choose Save.

Set Up a Redirect

Before you can associate your domain name with your website, you must redirect traffic from the www subdomain bucket to the root domain bucket. Then, Amazon S3 forwards any requests that are sent to the www subdomain bucket to the root domain bucket instead. By redirecting traffic in this way, you can maintain a single version of your website files in Amazon S3 while still supporting both the root and www subdomain versions of your website's address.

To redirect traffic from your www subdomain bucket to your root domain bucket

If you already have the Amazon S3 console open, skip step 1.

  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Choose the subdomain bucket you created, www.example.com, choose Properties, and then choose Static Website Hosting.

  3. Complete the Static Website Hosting pane as follows:

    1. Choose Redirect all requests to another host name.

    2. For Redirect all requests to, copy and paste the endpoint value of your root domain that was assigned by AWS, for example: example.com.s3-website-us-east-1.amazonaws.com

    3. Choose Save.

Test Your Website

You can verify that your static website is live on the Internet by using a web browser to navigate to the default URL assigned by Amazon Web Services.

To test your website

  1. Choose your root domain bucket, choose Properties, and then choose Static Website Hosting.

    The default URL assigned by AWS is the Endpoint. In the following image, this default URL is example.com.s3-website-us-east-1.amazonaws.com.

  2. Choose the endpoint. If your website is correctly deployed, you'll see its home page.

  3. (Optional) To verify that the subdomain bucket is properly redirecting visitors, try to access http://www.example.com.s3-website-us-east-1.amazonaws.com. If your website is correctly deployed, you are redirected to http://example.com.s3-website-us-east-1.amazonaws.com.

  4. (Optional) To verify that the error page is working, try to access a page on your new website that doesn't exist, such as http://example.com.s3-website-us-east-1.amazonaws.com/bogus.html. If your website is correctly deployed, you are redirected to your custom error page.

Anyone who has the endpoint URLs for your Amazon S3 buckets can view the contents of your static website in a web browser. If you don't have a registered domain name or you don’t plan to associate your website with a domain, we recommend cleaning up the resources so you no longer accrue charges. For more information on how to do so, see Clean Up.

Otherwise. perform the following additional tasks to associate your website with your domain name, and then clean up resources:

  1. Register Your Domain Name

  2. Associate a Domain Name with Your Website

  3. Speed Up Your Website

  4. Clean Up