AWS: Hosting Static Website On S3 Using a GoDaddy Domain

A Ravi Prashant
Tensult Blogs
Published in
5 min readSep 9, 2019

This Blog has been moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

In this article, I'm going to explain to you how you can Host Static website on S3 using a custom domain. Amazon S3 is a highly available and scalable solution.

Amazon S3 Overview

  1. Amazon S3 allows people to store objects (files) in “buckets” (directories).
  2. Buckets must have a globally unique name.
  3. Buckets are defined at the regional level.

Amazon Route53 Overview

  1. Route53 is a Managed DNS (Domain Name System).
  2. DNS is a collection of rules and records which helps the client understand how to reach a server through URLs.
  3. In AWS the most common records are A=URL to IPv4, CNAME=URL to URL, Alias: URL to AWS resource.
  4. You pay $0.50 per month per hosted zone.

Working of DNS Route53

When an end-user hits a website in its browser say example.com as the domain is purchased from GoDaddy.

Then the DNS request will go to the GoDaddy server and what we will do is we tell Godaddy don’t manage it yourself let AWS route53 service manage the DNS.

So the request will go to AWS Route53 Service and it will host all the DNS requests for our website and the website is hosted on S3. It will get the DNS IP address from the S3 and ultimately we will get the response with the given IP address and then the end-user browsers will directly connect over HTTP or HTTPS to the S3 backend where the website is hosted.

What do we need?

  1. A domain name from GoDaddy.
  2. S3 bucket with the same name as the domain name.
  3. S3 bucket with www subdomain name.
  4. AWS Route53 Public Hosted zone.
  5. Static website content.

STEPS

  1. Create an S3 bucket with a name the same as your domain name.
example.com bucket

2. Create another S3 bucket with www subdomain.

www.example.com bucket

3. Configure S3 main domain bucket to redirect to www subdomain

Select option 2 and give www subdomain name.

4. Upload website contents to www subdomain bucket.

5. Configure www bucket for website hosting.

Select option one

6. Add a bucket policy to make the bucket contents public.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect":"Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.example.com/*"
}
]
}

7. Create AWS route53 public hosted zone with the same name as the domain name.

8. Update GoDaddy NS with AWS provided NS.

Update your AWS NS in GoDaddy

9. In AWS Route53 create a recordset for the main domain and select Alias Checkbox to Yes and point it to S3 main bucket.

Select Alias checkbox to YES
Select S3 bucket website URL in Alias Target

10. In AWS Route53 create a recordset for www subdomain and point to S3 www bucket.

Select S3 bucket website URL

11. Access the website using your domain name.

Brief Explanation of the above steps is :

We need to have two s3 buckets now; why two?

Because generally when you assess your website you will put a name say example.com but it is an ideal way to host a website is with www subdomain that is www.example.com.

So how it is run in the AWS world? You create s3 buckets with both names and then you have this domain S3 bucket redirect the request to www subdomain.

So for that we need two S3 buckets one with main domain and one with www subdomain and then we will configure the main bucket to redirect traffic to www subdomain and we will actually host all our contents or upload to www subdomain bucket and we will configure this S3 bucket for website hosting in S3.

Now after we do this next thing we need to tell Godaddy that all the DNS will be managed by the AWS Route53 service. And for that, we will create the Route53 public Hosted zone which will give us the name servers of amazon site. We will update the NS to Godaddy DNS which will effectively tell GoDaddy that if you get an inquiry for domain name example.com just forward the request to amazon NS.

And then in the Amazon Route53 public hosted zone, we will create record sets for these two domains, main domain and www subdomain which points to corresponding S3 Buckets.

Note: It's important that the S3 bucket needs to be the same as the domain name.

Go to Route53 service of amazon and you should create a public hosted zone with the same name as your domain name.

So here I already created a hosted zone. If you click this and you see two records which are created by amazon are NS and SOA because this NS resolves your domain name to an IP address. Now copy NS to your GoDaddy DNS management.

Now we need to create a RecordSet and point it to S3 by using Alias target and point it to S3. Same way, add recordset for www subdomain & point it to S3 bucket.

Ok, so after completing the above-mentioned steps, we can verify that your website is running at the address www.example.com

Conclusion

I hope this guide helps you to host a static website on S3 using a custom domain. Share your queries in the comments section and look out for our next post as we share some of our learnings.

--

--