Menu
Getting Started with AWS
Hosting a Static Website

Step 2: Configure Your Buckets

When you configure your root domain bucket in Amazon S3 as a website, Amazon S3 delivers the files in that bucket to web browsers as if they were hosted on a web server. To make sure everyone can view the files for your website, you must add permissions to your root domain bucket. We also recommend that you enable logging to record information about traffic to your website.

To configure the buckets for your website, use Amazon S3 to complete the following tasks.

Add Permissions

When you first create an Amazon S3 bucket, only you can access the bucket and its contents. This default behavior ensures that you don't accidentally expose your data to other users. The point of a website, however, is to be visited, so you will apply a policy to the root domain bucket so that anyone can view its contents in web browser. For more information, go to Using Bucket Policies and User Policies in the Amazon Simple Storage Service Developer Guide.

To add permissions for the contents of 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. In the Buckets pane, choose your root domain bucket, choose Properties, choose Permissions, and then choose Add bucket policy to open the Bucket Policy Editor.

  3. Copy the following policy and paste it into the Bucket Policy Editor. In the Amazon Resource Name (ARN) for the resource in the "Resource" entry, replace example.com with the name of your bucket, and then choose Save. This policy gives everyone permission to view any file in the example.com bucket.

    Copy
    { "Version":"2012-10-17", "Statement": [{ "Sid": "Allow Public Access to All Objects", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::example.com/*" } ] }

    For more information on bucket policies, go to Using Bucket Polices and User Policies in the Amazon Simple Storage Service Developer Guide.

  4. For Permissions, choose Save.

Enable Logging

To track the number of visitors accessing your website, you must enable logging for the root domain bucket. Enabling logging is optional. If you don't want to track traffic to your website, you can skip the following procedure.

With logging enabled, you can track information such as data in and out of your bucket and the IP addresses of whoever is accessing your bucket. There is no extra charge for enabling logging on a bucket; however, you will accrue charges to store the resulting log files in the bucket that you specify. (You can delete the log files from this bucket at any time.) Amazon S3 does not assess data transfer charges for log file delivery, but does charge the normal data transfer rate for accessing the log files. For more information, see Server Access Logging in the Amazon Simple Storage Service Developer Guide.

To enable logging for your root domain bucket

If you have the Amazon S3 console is 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 Logging.

  3. Complete the Logging pane as follows:

    1. Select the Enabled check box.

    2. For Target Bucket, choose the bucket that you created for the log files, logs.example.com.

    3. For Target Prefix, type root/. This setting groups the log data files in a folder named root in the bucket so that they will be easy for you to locate later.

    4. Choose Save.