How to host your React App on your custom domain or its sub-domain using AWS Amplify and Route 53
Tags: aws, react
Published: 2021-05-30 08:00:37

Hey everyone, hope y'all are safe and sound.
I recently purchased a custom domain for my portfolio from [GoDaddy](https://godaddy.com/). This was my first time when I was purchasing domain and was all set to host my portfolio on it.

The process was not straight forward, also I couldn't find enough help from the internet. But after few hit&trials, I finally managed to accomplish my goal.

Therefore I am jotting down few steps from my experience, which one can follow to deploy their react app in the easiest way on their custom domain using AWS Amplify.

**NOTE:** I am assuming that you already have a react-app ready and pushed to your github(or any other version control service) repository.

# PART-1: DEPLOY REACT APP ON AWS AMPLIFY

1. Visit [aws.amazon.com](https://aws.amazon.com/)
2. Create an account on AWS.
3. You will be required to add your basic details, and also a payment method.
**NOTE**: You don't need to pay for anything on AWS in the part-1 of this guide, this payment method will just be used when you exclusively use a paid service.
4. Once you sign-up, go to [AWS console](https://console.aws.amazon.com)
5. On the top-left corner, can be seen services dropdown which will enlist the services provided by AWS in the following way:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwhvd5esfqd1on4qfaas.png)
6. Look around for _AWS Amplify_ that should be present under _Front-end Web & Mobile_ category.
7. Open AWS Amplify, and scroll to bottom of the page to reach here:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwlcrpxbbqdzj295c4z2.png)
8. As we want to host our react-app, we will click on **Get Started** button under the _**Deliver**_ section.
9. Select any of these version control services where your git repository lies:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqp3yghyhjv0wu1ajzyq.png)
10. A new user will be required to authorize the selected service.
11. Once the authentication is successful, you will be presented with a list of your repositories.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s46pumh184gf3a715nnu.png)
12. Once you select the repository, another dropdown with the available branches will appear.
13. Select the branch which you want to deploy and click on **Next**.
14. Amplify will now read the build settings of your app from your repository and show you a preview of it.
You do not need to change anything, so just click on **Next**.
15. Now, a final review will be shown before deploy.
Again no changes are to be made, so click on **Save and deploy**
16. Wait for the deploy to complete:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i01mp3g7yo5h0wus92xj.png)
17. BOOM! Your react app is now finally deployed and you can test it on the **.amplifyapp.com** domain url provided down there.



# PART-2: ADD A CUSTOM DOMAIN
**NOTE:** You can purchase a domain from GoDaddy, Google Domains, AWS Route 53, etc.

1. From the services provided by AWS (in point 5 of PART-1), select Route 53.
2. Click on **Create Hosted Zone**.
**NOTE:**
  A. We are doing this so that we don't have to manually add DNS 
     records to our domain's DNS settings.
  B. The Hosted zone name should be same as your domain 
     name(without https:// and www)
**NOTE**: Hosted Zone is a paid service, and it costs around 0.59$/month(including taxes) for first 25 hosted zones.
3. Fill the domain name. You can keep the zone as public.
 ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s72hwynuwb4n9b8u3ygi.png)
4. Once the hosted zone is created, open it to find the four nameservers there:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qouv288ktu6kflnkl32.png)
5. Go to GoDaddy or any other service from where you have purchased your domain.
6. Go to domain settings, and look for **nameservers**
7. Edit the nameservers, remove the default ones and add the 4 nameservers(in point 4).
This allows AWS Route 53 to automatically manage the DNS to redirect the traffic.
8. Now, go back to AWS Amplify, where you hosted your React App.
9. In the app-settings in right bar, select the Domain Management option:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6u2gxfsepcgj1aj47srj.png)
10. Click on **Add Domain** button.
11. On the next screen, an input field will be present, which on focus will automatically suggest you the name of the hosted zone that you created.
12. Select that hosted zone and click on **Configure Domain**.
13. Now the subdomain settings will appear. 
A. If you want to host your app on the root of your domain (say _example.com_), then no changes in these settings are required.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsy634tygf86rixbb9le.png)
B. If you want to host your app on a subdomain of your
domain(say _blog.example.com_), then click on **Exclude Root** and replace **www** with your sub-domain(here: _blog_).
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/87zf21qwqmlwz24wagz0.png)

14. Click on **Save**. Now sit back and relax, and let AWS Amplify do the job:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cz1tbiy3w6l8b3u89oil.png)
**NOTE:** Time taken in this process can vary, so a bit of patience is expected.