HostingWebsiteOnS3Setup

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.

Topics

Step 1: Creating a Bucket and Configuring 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, see How Do I Create an Amazon S3 Bucket? in Amazon Simple Storage Service Console User Guide.

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

  3. Open the bucket Properties pane, choose Static Website Hosting, and do the following:

    1. Choose Use this bucket to host a website.

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

    3. Choose Save to save the website configuration.

    4. Write down the Endpoint.

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

Editing Block Public Access Settings

By default, Amazon S3 blocks public access to your account and buckets. If you want to use a bucket to host a static website, you can use these steps to edit block public access settings:

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

  2. Select the bucket that you have configured as a static website, and choose Edit public access settings.
    [Image NOT FOUND]

  3. Clear Block all public access, and choose Save.
    [Image NOT FOUND]

  4. In the confirmation box, enter confirm, and then choose Confirm.
    [Image NOT FOUND]

    Under S3 buckets, the Access for your bucket updates to Objects can be public. You can now add a bucket policy to make the objects in the bucket publicly readable. If the Access still displays as Bucket and objects not public, you might have to edit the block public access settings for your account before adding a bucket policy.

Step 3: Adding a Bucket Policy That Makes Your Bucket Content Publicly Available

  1. In the Properties pane for the bucket, choose Permissions.

  2. Choose Bucket Policy.

  3. To grant public read access for your website, copy the following bucket policy, and paste it in the Bucket policy editor.

    1. {
    2. "Version":"2012-10-17",
    3. "Statement":[{
    4. "Sid":"PublicReadForGetBucketObjects",
    5. "Effect":"Allow",
    6. "Principal": "*",
    7. "Action":["s3:GetObject"],
    8. "Resource":["arn:aws:s3:::example-bucket/*"
    9. ]
    10. }
    11. ]
    12. }
  4. In the policy, replace example-bucket with the name of your bucket.

  5. Choose Save.

    In your Amazon S3 bucket listing, the Access for your bucket updates to Public.

Step 4: Uploading an Index Document

  1. Create a document. Give it the same name that you gave the index document earlier.

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

    For instructions, see How Do I Upload Files and Folders to an S3 Bucket? in the Amazon Simple Storage Service Console User Guide.

Step 5: Testing 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 AWS Region where you deployed your bucket.

Depending on your Region, Amazon S3 website endpoints follow one of these two formats:

http://bucket-name.s3-website.Region.amazonaws.com
http://bucket-name.s3-website-Region.amazonaws.com

For a complete list of Amazon S3 website endpoints, see Amazon S3 Website Endpoints.

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 root domain support to serve requests for both 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.