Configuring A Static Website On Amazon S3
Configuring A Static Website On Amazon S3
Configuring A Static Website On Amazon S3
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
To create a bucket
1. Sign in to the AWS Management Console and open the Amazon S3 console at
https://console.aws.amazon.com/s3/ (https://console.aws.amazon.com/s3/) .
2. Choose Create bucket.
3. Enter the Bucket name (for example,
example.com ).
4. Choose the Region where you want to create the bucket.
Choose a Region that is geographically close to you to minimize latency
and costs, or to
address regulatory requirements. The Region that you choose
determines your Amazon S3
website endpoint. For more information, see Website endpoints (./WebsiteEndpoints.html) .
5. To accept the default settings and create the bucket, choose
Create.
1. Sign in to the AWS Management Console and open the Amazon S3 console at
https://console.aws.amazon.com/s3/ (https://console.aws.amazon.com/s3/) .
2. In the Buckets list, choose the name of the bucket that you want to
enable static website
hosting for.
3. Choose Properties.
4. Under Static website hosting, choose Edit.
5. Choose Use this bucket to host a website.
6. Under Static website hosting, choose Enable.
7. In Index document, enter the file name of the index document,
typically index.html .
The index document name is case sensitive and must exactly match the file name of the
HTML index document that you plan to upload to your S3 bucket. When you configure a
bucket for website hosting, you must specify an index document.
Amazon S3 returns this
index document when requests are made to the root domain or any of the
subfolders. For
more information, see Configuring an index document (./IndexDocumentSupport.html) .
8. To provide your own custom error document for 4XX class
errors, in Error document, enter
the custom error document file name.
The error document name is case sensitive and must exactly match the file name of the
HTML error document that you plan to upload to your S3 bucket. If you don't specify a
custom error document and an error occurs, Amazon S3 returns a
default HTML error
document. For more information, see Configuring a custom error document
(./CustomErrorDocSupport.html) .
9. (Optional) If you want to specify advanced redirection rules, in Redirection rules, enter
JSON to describe the rules.
For example, you can conditionally route requests according to specific object key
names
or prefixes in the request. For more information, see Configure redirection rules to use
advanced conditional redirects (./how-to-page-redirect.html#advanced-conditional-redirects) .
10. Choose Save changes.
Amazon S3 enables static website hosting for your bucket. At the bottom of the page,
under Static website hosting, you see the website endpoint for your bucket.
11. Under Static website hosting, note the Endpoint.
The Endpoint is the Amazon S3 website endpoint for your bucket.
After you finish
configuring your bucket as a static website, you can use this endpoint to test your
website.
Warning
Before you complete this step, review Blocking public access to your Amazon S3
storage (./access-control-block-public-access.html) to ensure that you understand and
accept the risks involved with allowing public access. When you turn off block public
access settings to make your bucket public, anyone on the internet can access your
bucket. We recommend that you block all public access to your buckets.
2. Choose the name of the bucket that you have configured as a static website.
3. Choose Permissions.
4. Under Block public access (bucket settings), choose Edit.
5. Clear Block all public
access, and choose Save changes.
Warning
Before you complete this step, review Blocking public access to your Amazon S3
storage (./access-control-block-public-access.html) to ensure you understand and
accept the risks involved with allowing public access. When you turn off block
public access settings to make your bucket public, anyone on the internet can
access your bucket. We recommend that you block all public access to your
buckets.
Amazon S3 turns off Block Public Access settings for your bucket. To create a public, static
website, you might also have to edit the Block Public Access settings
(https://docs.aws.amazon.com/AmazonS3/latest/user-guide/block-public-access-account.html) for
your account
before adding a bucket policy. If account settings for Block Public Access are
currently turned on, you see a note under Block public access (bucket settings).
Important
The following policy is an example only and allows full access to the contents of your
bucket. Before you proceed with this step, review How can I secure the files in my
Amazon S3 bucket? (https://aws.amazon.com/premiumsupport/knowledge-
center/secure-s3-resources/) to ensure that you understand the best practices for
securing the files in your S3 bucket and risks involved in granting public access.
"Version": "2012-10-17",
"Statement": [
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::Bucket-Name/*"
If you get an error message and cannot save the bucket policy, check your account and
bucket Block Public Access settings to confirm that you allow public access to the bucket.
Step 5: Configure an index document
When you enable static website hosting for your bucket, you enter the name of the index
document (for example, index.html ). After you enable static website hosting for the bucket,
you upload an HTML file with this index document name to your bucket.
<head>
</head>
<body>
<h1>Welcome to my website</h1>
</body>
</html>
4. In the Buckets list, choose the name of the bucket that you want to use to host a static
website.
5. Enable static website hosting for your bucket, and enter the exact name of
your error
document (for example, 404.html ). For more
information, see Enabling website hosting
(./EnableWebsiteHosting.html) .
Note
Amazon S3 does not support HTTPS access to the website. If you want to use HTTPS,
you can use Amazon CloudFront to serve a static website hosted on Amazon S3.
For more information, see How do I use CloudFront to serve a static website hosted
on Amazon S3? (http://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-
serve-static-website/) and Requiring HTTPS for communication between viewers and
CloudFront (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-
https-viewers-to-cloudfront.html) .
Step 8: Clean
up
If you created your static website only as a learning exercise, delete the AWS
resources that
you allocated so that you no longer accrue charges. After you delete
your AWS resources, your
website is no longer available. For more information, see
Deleting a bucket (./delete-
bucket.html) .
© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.