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
element to set error 4XX page that will redirect all error pages to this error page.
PUT /?website HTTP/1.1
Date: Thu, 27 Jan 2011 12:00:00 GMT
Authorization: authorization keys
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.
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.