Documentation to create a Static Website using Amazon S3
Intro
To create and configure a simple stattic website in S3 which consist files like HTML, CSS, JavaScript, fonts and image
Create S3 Bucket**
-
Begin by navigating to the GitHub repository for the code.
-
Select the error.html file.
-
Above the code area, click Raw.
-
Right-click and select Save Page As, and save the file as error.html.
Note: If you are using Safari as your web browser, ensure that you remove the .txt from the end of the filename. Also, ensure that the Format is Page Source. When asked whether you want to save the file as plain text, click Don't Append.
-
Repeat this for the index.html file.
-
From the AWS Management Console, navigate to S3.
-
Click Create bucket.
-
Set the following values:
- Bucket name: my-bucket- with the AWS account number or another series of numbers at the end to make it globally unique
- Region: US East (N. Virginia) us-east-1
-
In the Block Public Access settings for this bucket section, un-check Block all public access.
- Ensure all 4 permissions restrictions beneath it are also un-checked.
-
Check the box to acknowledge that turning off all public access might result in the bucket and its objects becoming public.
-
Leave the rest of the settings as their defaults.
-
Click Create bucket.
-
Click the radio button next to the bucket name to select it.
-
Click Copy ARN.
-
Select the bucket name.
-
Click Upload.
-
Click Add files, and upload the
error.htmlandindex.htmlfiles you previously saved from GitHub. -
Leave the rest of the settings as their defaults.
-
Click Upload.
-
Click Close in the upper right.
-
Click the Properties tab.
-
Scroll to the bottom of the screen to find the Static website hosting section.
-
On the right in the Static website hosting section, click Edit.
-
On the Edit static website hosting page, set the following values:
- Static website hosting: Enable
- Hosting type: Host a static website
- Index document: index.html
- Error document: error.html
-
Scroll down, and click Save changes.
-
Scroll back down to the Static website hosting section.
-
Open the listed endpoint URL in a new browser tab. You'll see a
403 Forbiddenerror message. -
Back in S3, click the Permissions tab.
-
In the Bucket policy section, click Edit.
-
In the Policy box, enter the following JSON statement (replacing
<BUCKET_ARN>with the bucket ARN provided right above the Policy box):{ "Version":"2012-10-17", "Statement":[{ "Sid":"PublicReadGetObject", "Effect":"Allow", "Principal": "*", "Action":["s3:GetObject"], "Resource":["<BUCKET_ARN>/*"] }] }Note: Ensure the trailing /* is present so the policy applies to all objects within the bucket.
-
Click Save changes.
-
Refresh the browser tab with the static website (the endpoint URL you opened a minute ago). This time, it should load the site correctly.
-
Add a
/at the end of the URL and some random letters (anything that's knowingly an error). This will display yourerror.htmlpage.