Host a static website with https in Amazon s3 with custom Domain

Harshal kondke
3 min readAug 30, 2020

Hosting static pages can really very helpful sometimes. Either its just a server down notification page or a complete website. Even when using backed its good idea to host static pages in S3 as its Highly available and scalable service.

user getting data from s3 bucket

After hosting a static website, it is possible to make it secured with https within AWS itself but its more complicated and takes time. So, we will be using CloudFlare.

CloudFlare provides one click SSL certificate and also multiple other features as well like analytics on amount of data share, firewall at DNS level, minimize html files and makes it faster while loading. All this can be done with few clicks and its highly easy for beginners to setup without even understanding the complexity of DNS routing. (If time is not your problem, I’ll recommend setting everything in AWS. you can refer this blog for the same)

Requirements

  • AWS account
  • CloudFlare Account
  • HTML pages or complete site

Step 1:

No matter which domain provider you are using, we will use CloudFlare(Reasons mentioned at top)

LogIn to your CloudFlare account and setup the basic domain. Then as steps suggest, change your domains Name Servers to CloudFlares Name servers.

Step 2:

Log into your AWS account.

Create a bucket with same name as your domain with www as subdomain like www.example.com

Add your website static pages to this bucket.(You can drag & drop) and select all elements and make it public.

We want to make all the objects visible to public. So change the bucket policy as shown in below.

Under Properties tab select Static website Hosting and then select Use this bucket to host a website. As shown in below fig, setup Index document and error document. Copy bucket EndPoint we will need it to setup domain name

Step 3:

Now, create another bucket with name as same of your domain name. like example.com As we want to redirect all the request to www.example.com from example.com as it is common practice in web.

In this bucket, make following two changes.

Step 4:

We have setup our s3 bucket. you can check it with bucket EndPoint.

Now, Log In to CloudFlare. we already setup NS to CloudFlare so we can directly start working.

Set SSL is true.

and add new CNAME record. host www and value is Endpoint of first bucket. (remove http:// from value while adding to CNAME record)

Create another CNAME recordhost @ and value is Endpoint of second bucket. (remove http:// from value while adding to CNAME record)

and That’s it.

You can check the domain. and our website is up and ruining with https and custom domain.

Conclusion:

All though i suggest going a harder way and setting up SSL certificate in AWS with CloudFront distribution. but if you are in hurry cloud flare can help you.

Happy Coding.

PS: you can check your sites analytics in CloudFlare.

--

--