Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)
« 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...

Example: Setting Up a Static Website

You can configure an Amazon S3 bucket to function like a website. This example walks you through the steps of hosting a website on Amazon S3. In the following procedure, you will use the AWS Management Console to perform the necessary tasks:

  1. Create an Amazon S3 bucket and configure it as a website (see To create a bucket and configure it as a website ).

  2. Add a bucket policy that make the bucket content public (see To add a bucket policy that makes your bucket content publicly available ).

    The content that you serve at the website endpoint must be publicly readable. You can grant the necessary permissions by adding a bucket policy or using Access Control List (ACL). Here we describe adding a bucket policy .

  3. Upload an index document (see To upload an index document).

  4. Test your website using the Amazon S3 bucket website endpoint (Test your website).

To create a bucket and configure it as a website

  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Create a bucket.

    For step-by-step instructions, go to Create a bucket in Amazon Simple Storage Service Console User Guide.

    For bucket naming guidelines, see Bucket Restrictions and Limitations. If you have your registered domain name, for additional information about bucket naming, see Customizing Amazon S3 URLs with CNAMEs.

  3. Open the bucket Properties panel, click Static Website Hosting and do the following:

    1. Select the Enable website hosting.

    2. In the Index Document box, add the name of your index document. This name is typically index.html.

    3. Click Save to save the website configuration.

    4. Note down the Endpoint.

      This is the Amazon S3 provided website endpoint for your bucket. You will use this endpoint in the following steps to test your website.

To add a bucket policy that makes your bucket content publicly available

  1. In bucket Properties panel, click the Permissions.

  2. Click Add Bucket Policy.

  3. Copy the following bucket policy, and then paste it in the Bucket Policy Editor.

    {
      "Version":"2012-10-17",
      "Statement":[{
    	"Sid":"PublicReadForGetBucketObjects",
            "Effect":"Allow",
    	  "Principal": "*",
          "Action":["s3:GetObject"],
          "Resource":["arn:aws:s3:::example-bucket/*"
          ]
        }
      ]
    }
  4. In the policy, replace example-bucket with the name of your bucket.

  5. Click Save.

To upload an index document

  1. Create a document. The file name must be same as the name that you provided for the index document earlier.

  2. Using the console, upload the index document to your bucket.

    For step-by-step instructions, go to Uploading Objects into Amazon S3 in the Amazon Simple Storage Service Console User Guide.

Test your website

  • Enter the following URL in the browser, replacing example-bucket with the name of your bucket and website-region with the name of the region where you deployed your bucket. For information about region names, see Website Endpoints ).

    http://example-bucket.s3-website-region.amazonaws.com

    If your browser displays your index.html page, the website was successfully deployed.

Note

HTTPS access to the website is not supported.

You now have a website hosted on Amazon S3. This website is available at the Amazon S3 website endpoint. However, you might have a domain such as example.com that you want to use to serve the content from the website you created. You might also want to use Amazon S3's root domain support to serve requests for both the http://www.example.com and http://example.com. This requires additional steps. For an example, see Example: Setting Up a Static Website Using a Custom Domain.