download free 30 days trial version buy bucket explorer
Documentation  Download  Purchase  Support  FAQs   Forum   ScreenShots & Demos

Set Amazon S3 Bucket as S3 Website using PUT Bucket Website

Configure Amazon S3 Bucket as a Website by Sending HTTP PUT Request to Amazon S3 Server

You can configure an Amazon S3 Bucket  under your AWS account, as a website by sending an HTTP Reuest. To authenticate the request, you need to be the Bucket owner and you also need to have S3:PutBucketWebsite permission. As a Bucket owner, you may also write a bucket policy that grants S3:PutBucketWebsite permission to other users and allow them to set website configuration.

You can configure an S3 Bucket as a Website programatically by using Amazon S3 API (PUT Bucket Website) in your program, or alternatively, you can use Bucket Explorer tool, to configure the Bucket as a Website using the UI. The following sections talk about how you can use Amazon S3 REST API (PUT Bucket Website) or Bucket Explorer to configure the Bucket as a website. We will only talk about Amazon S3 REST API in this documentation. You can read Amazon S3 Documentation to get details on SOAP APIs.

Set S3 Bucket as S3 Website using Amazon REST API (PUT Bucket Website)

You can request PUT Bucket Website from your program to configure a Bucket as Website. For that, you only need to use Request headers common to all operations and use Request elements to be able to add routing rules that will specify and describe conditions to redirect requests and information on the destination.

Also, an index document must be provided for the Bucket in the website configuration.

  • To set Index Document
    To set Index Document, we need to specify IndexDocument element in PUT request.
  • To set Error Document
    To set error 4XX page, you need to request PUT Bucket website. For that, you need to use only Request headers common to all operations and use Request elements to add routing rules that will describe redirecting requests conditions and information on the destination. In this case, you will use ErrorDocument element to set error 4XX page that will redirect all error pages to this error page.

Syntax:


PUT /?website HTTP/1.1
Host: example.com.s3.amazonaws.com
Content-Length: 256
Date: Thu, 27 Jan 2011 12:00:00 GMT
Authorization: authorization keys

<WebsiteConfiguration xmlns=”http://s3.amazonaws.com/doc/2006-03-01/”>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>SomeErrorDocument.html</Key>
</ErrorDocument>
</WebsiteConfiguration>
 

Set S3 Bucket as S3 Website using Bucket Explorer

If you are not a programmer and do not want to go through the hassle of writng code, you can set and configure S3 Bucket as S3 Website using Bucket Explorer user interface.

How to set S3 Bucket as S3 Website

Now you can easily host your static website on the S3 Bucket. This feature will treat your Bucket as website domain means. When you type “http://<bucketname>.s3-website-<region>.amazonaws.com” in the browser, it will show you the default page in the browser automatically like distribution does. This feature also allows you to define error 4XX page to display if error occurs. Remember to access content on the website endpoints, make all your content publicly readable and do not use Dev Pay or Requester Pay for S3 Bucket because it does not allow access by S3 Website Endpoint. For that you will receive a 404 Access Denied response.

Note: Index document cannot be empty and do not add slash character with document page.

Bucket Explorer helps you Set/Remove S3 Website for Selected Bucket option to treat your Bucket like website domain.

how to set S3 Website on bucket?

Steps to Host your Website on Amazon S3 using Bucket Explorer:

  1. First step is to sign up on Amazon S3.
  2. Download the latest version of Bucket Explorer and install it. Login to S3 using Bucket Explorer (Amazon S3 Tool).
  3. Create Bucket . Enter the name of the Bucket same as your website and select the region where you want to create Bucket.
  4. Select the newly created Bucket and Upload all web pages, images, CSS, and other static files from your desktop to your Amazon S3 Bucket.
  1. Set Permission on all objects of the Bucket as “Public Readable”.
  2. Click on “Advanced” button in Bucket table toolbar. It will you show drop down options. Select “S3 Website” among them. Click on “Set S3 Website” option.
  3. Set Website window will appear with two options:
    • Index page
    • Error page

    Click on Set button. Set your default page (i.e. index.html) as a Home page. Save the changes. Index document cannot be empty and do not add slash character with document page.
    Note: It’s not possible to specify specific 4XX documents such as 404, 403, and so on; all errors will have to be directed to the same error page. So you can set only one error page.

  4. Now you can easily host your static website on the S3 Bucket. This feature will treat your Bucket as a website domain means. When you type “http://<bucketname>.s3-website-<region-endpoint>.amazonaws.com” in your browser, it will show your default page in browser automatically like distribution does.
  5. Now log in to your domain hosting service and add a new CNAME Record for your domain.
    E.g. mysite.s3-website-us-west-1.amazonaws.com with CNAME as www.mysite.com
  6. Now you can access your website with URL http://www.mysite.com and Amazon returns its index page in response as http://www.mysite.com/index.html