This page looks best with JavaScript enabled

Host a static website on AWS S3

 ·  β˜• 2 min read

Prepare


If you use Hugo to create a static website,
you need to modify baseURL param in config.toml
Fill in your url, e.g. https://blog.jihongo.com

Run CMD, and enter hugo command,
the website will be built to the public folder.

The files inside are the content of the entire website.

S3

First, Click S3


select s3

Click Create bucket


create bucket

Fill in Bucket name, Region can select Tokyo or Singapore or others,
disable Block all public access


create bucket detail

click the bucket name


create bucket finished

Switch to Properties tab and click Static website hosting


click static website hosting

Select Use this bucket to host a website

Index document fill in index.html
Error document fill in 404.html
Copy the link of Endpoint, it will be used later.


static website hosting configuration

Switch to Overview tab, upload all your files from the public folder.
(DO NOT directly upload the public folder)


upload files

upload files step 1

Grant public read access to this object(s)


upload files step 2

Standard


upload files step 3

Upload


upload files step 4

OK

CloudFront

Click CloudFront


select cloudfront

Click Create Distribution


select cloudfront

Click Web


cloudfront select web

After forward the page,
swipe to the middle to Request or Import a Certificate with ACM


cloudfront create distribution detail create ssl

Fill in *.YOUR_DOMAIN_NAME


certificate create step 1

Select Email validation or DNS validation
Here use Email validation


certificate create step 2

I do not add tags


certificate create step 3

Review


certificate create step 4

You can check which e-mail it will send to, and make sure you can receive it.
One is admin@YOUR_DOMAIN_NAME


certificate create step 5

My domain was purchased from Google Domains

Add admin@YOUR_DOMAIN_NAME and forward it to your own e-mail.


google domain alias email

Valid it


certificate mail

Click I Approve


certificate auth

Success


certificate auth success

Go back and refresh AWS Certificate Manager tab, the State will be Enabled.


certificate manager refresh

Go back to the Create Distribution page.

Origin Domain Name select Amazon S3 Buckets

Viewer Protocol Policy select Redirect HTTP to HTTPS


cloudfront create distribution detail 1

Enable Compress Objects Automatically


cloudfront create distribution detail 2

Price Class depends on you

Fill in the Alternate Domain Names

Select Custom SSL Certificate


cloudfront create distribution detail 3

Others set default


cloudfront create distribution detail 4

After create distribution and wait for some time, the Status will change to Deployed.

Copy the Domain Name YOURS.cloudfront.net, use it later.

Click ID to configuare.


cloudfront done

Switch to Origins and Origin Groups tab, select it and edit


cloudfront origins edit

Paste the link of Endpoint to Origin Domain Name


cloudfront origins edit done

If you have uploaded a static website and the settings are all right.
You can see your static website (HTTP) by entering the link of Endpoint in the browser
You can also enter YOURS.cloudfront.net (HTTPS)

Finally, go to your domain name provider.
Add a type: CNAME, data: YOURS.cloudfront.net

For me, CNAME = blog


google domain add cname

Wait for some time, it will work.


done

Done

Share on
Support the author with

JIHONGO
WRITTEN BY
JIHONGO
A Person