AWS static website hosting with https for a custom domain

Selva Kumar Rajendran
3 min readFeb 2, 2021

--

AWS Static web hosting flow

Introduction

If a static web site to be hosted with aws using s3, also if https needs to be enabled for the custom domain then, this document might help to achieve.

AWS Services used

· S3 — Static files like html, image, JavaScript files to be uploaded into s3 service

· Cloud Front — Which routes http traffic to https

· Route 53 — For domain registration and hosted zone record creation.

Create Domain in Route53

Firstly, domain should be registed in Route53. This should be the very first step. Example if want your site to be hosted with https://selva.scooby.link, then register a domain name scooby.link

Domain Registration

After successful registration below steps to be followed.

S3 Service

Two s3 buckets to be created, bucket name should be inline to the domain which I have created in the above domain registartion process, in my case which is scooby.link & selva.scooby.link

Bucket # 1

· Scooby.link — Upload all the files to the bucket. Enable — Static website hosting option. In the example below I have enabled static website hosting, and my entry file is index.html which I have provided in the index document.

s3 First bucket

· Permissions [Enable public access to the bucket]

{

“Version”: “2012–10–17”,

“Statement”: [

{

“Effect”: “Allow”,

“Principal”: “*”,

“Action”: “s3:GetObject”,

“Resource”: “MY_BUCKET_ARN/*”

}

]

}

Bucket # 2

· Selva.scooby.link

# Enable static website hosting

# Choose ‘Redirect requests for an object’

# Enter ‘Hostname’ where the Record set created in the hosted zone using the previous s3 bucket to be entered.

# Protocol https to be selected.

s3- second bucket

In my case I have given scooby.link in the host name.

Cloud Front

· Create a web distribution.

· Enter “Origin Domain name” where enter the s3 bucket # 1 instead selecting from the drop down. Get the details from the bucket # 1, properties tab as highlighted in the image below.

· Choose “Viewer Protocol Policy” as Redirect http to https

· Enter “Alternate Domain Names” subdomain for which traffic to be routed to https, in my case selva.scooby.link

· Choose the SSL certificate, if the certificate for the custom domain was not created please create and select the certificate for the subdomain(selva.scooby.link) as mentioned in the above step.

Route 53

· Domains — Register a domain then, verify the contact. [This should be the first step as defined before]

Hosted Zone

> Create “A” type record for the domain “scooby.link”which should route traffic to the s3 bucket # 1 as mentioned below.

scooby.link — A record

> Create another “A” type record for the subdomain for which https redirect should happen “web.scooby.link” for which traffic to be routed to “CloudFront” and choose the CloudFront created in cloudfront section above.

After all the above mentioned steps, should load the static web page which route traffic to https as expected.

Thanks for reading!

--

--

Selva Kumar Rajendran
Selva Kumar Rajendran

Written by Selva Kumar Rajendran

Developer, AWS SAA, Software Architect — Who loves to learn new technologies and try to apply technical skills practially on different domains.

Responses (2)