Setting up an AWS Route53 domain on Begin.

Tags: aws, dns, serverless, route53
Published: 2021-01-11 10:37:46

## Introduction

> **This article will give you a complete walk-through for setting up your Route53 domain on your Begin app. The entire process should take no longer than 10 minutes.**

You may use a free registrar-based DNS to host your domain on Begin such as Godaddy, Namecheap, One.com, etc., but Route53 is the preferred registrar and DNS management system for Begin users because:

- It's integrated with Amazon's other cloud services.
- Your DNS will resolve from 15+ locations worldwide, making your website faster for your end-users.
- Route53 is a DNS management system (Smart DNS) compared to all the others, which are merely domain registrars with a limited feature set for manipulating DNS.

First, we will learn how to set up our domain and DNS in Route53, and then we will finish by mapping our domain to Begin. Without further ado!

## Step 1: Sign up for AWS

Don't be discouraged by this section, as it may seem overly tedious to create an account. This section is important and will open up the powers and services of AWS in a safe manner.

Create an AWS account if you don't already have one. After you create your AWS account, you must take a few prerequisite actions to set up your account for everyday tasks properly.

When you first create an AWS account, you start with one identity with total access to all AWS services and resources in the account. This identity is called the AWS account root user.

"Amazon strongly recommends that you do not use the root user for your everyday tasks, even the administrative ones. Instead, adhere to the best practice of using the root user only to create your first IAM user. Then securely lock away the root user credentials and use them to perform only a few account and service management tasks." - AWS.

> [Learn more about the AWS account root user and how to set up your identity management correctly.](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html)

## Step 2: Purchase/Transfer domain

Depending on your situation, you may be ready to purchase a brand new domain or transfer a domain from a different registrar. Buying a brand new domain is a quick and straightforward process while transferring in a domain will vary from each user's situation. I'll cover how to do both below.

### Purchase domain

To purchase a domain, navigate to the Route53 service in your AWS management console and check to see if the domain you want is available. If it is available, follow the instructions to purchase the domain.

![Screen Shot 2021-01-06 at 10.24.54 AM](https://dev-to-uploads.s3.amazonaws.com/i/vsh391grupxolroxw0ex.png)
 
### Transfer Domain

To transfer the registration for a domain to Amazon Route 53, carefully follow the procedures in this article from the AWS documentation.

[Transferring registration for a domain to Amazon Route 53
](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-transfer-to-route-53.html)

## Step 3: Setup DNS

Now that we have the domain of our choice ready to go, we must add it to a hosted zone first. If you purchased your domain through Route53, AWS would have automatically created a domain's hosted zone. If you transferred a domain from another registrar, then navigate to the `Hosted Zones` page, and enter the required information. Make sure it is set to `public hosted zone`. 

![Screen Shot 2021-01-06 at 10.42.53 AM](https://dev-to-uploads.s3.amazonaws.com/i/zcq77znet0pxlry2bzxd.png)
  

## Step 4: Map domain to Begin

Begin allows you to add your domain to your Begin app through a simple process called [domain mapping (also sometimes called host mapping).](https://docs.begin.com/en/getting-started/domains)

What most people want is a `naked domain`. A naked domain (also referred to as a zone apex) is simply a domain set up to respond to requests without a subdomain. For example:

`https://begin.com` is a web address using a naked domain
`https://docs.begin.com` has a subdomain and is thus not a naked domain.

Begin supports mapping naked domains, but your current DNS provider needs to support it, which is why we recommend AWS Route53.

### Mapping Domain

Navigate to the backend of your Begin app and click the `Domains` tab. Once there, click `Get Started` and follow the instructions.

![Screen Shot 2021-01-06 at 11.20.36 AM](https://dev-to-uploads.s3.amazonaws.com/i/eapbd59qo2z0kchw2bo4.png)

### Adding DNS records

In step 2 of mapping your domains to Begin, you'll need to add two `CNAME` values to your DNS provider to verify ownership of the domain(s) and generate your SSL certificates for HTTPS. 

Head back to the `hosted zone` of your domain in the Route53 console. Click `Create Record`. On this screen, you will first add the `production` `CNAME` value and then secondly the `staging` `CNAME` value. Let's begin with the `production` value. Everything in the red is what has to be entered into the console.

![Screen Shot 2021-02-01 at 9.28.04 AM](https://dev-to-uploads.s3.amazonaws.com/i/o4pkht6sgd3new0g14v0.png) 

- Make sure `Routing policy` is set to `Simple routing`.
- Change `Record type` to `CNAME`.
- Add the `Name` from Begin to the `Record name` value.
- Add the `Value` from Begin to the `Value` value.
- Click `Create record`.
- Repeat process for `staging` `CNAME`.

![Screen Shot 2021-01-06 at 11.31.06 AM](https://dev-to-uploads.s3.amazonaws.com/i/bu5qw74yx4eidnw37b0p.png)
 
### Alias

Now that we've added the `CNAME` records for our SSL certificates, we can add our last `CNAME` and `A` records that will officially map our domains to our begin app.

![Screen Shot 2021-01-14 at 4.04.35 AM](https://dev-to-uploads.s3.amazonaws.com/i/nvwqoy55vfsfkddmzmav.png)
 
Head back to the `Hosted Zone` section in your Route53 DNS console for the domain you are working on. First, let's add the `CNAME` record for our staging domain.

- Make sure `Routing policy` is set to `Simple routing`.
- Change `Record type` to `CNAME`.
- Add the `Name` from Begin to the `Record name` value.
- Add the `Value` from Begin to the `Value` value.
- Click `Create record`.

![Screen Shot 2021-02-01 at 9.22.59 AM](https://dev-to-uploads.s3.amazonaws.com/i/lamqxxmyd7rm54zblxfx.png) 

- Click `Create Record`.
- Change `Record type` to `A`.
- Make sure `Routing policy` is set to `Simple routing`.
- Make sure `Record type` is set to `Routes traffic to an Ipv4 address and some AWS resources`.
- In the `Value/Route traffic to` sections:
    - Set to `Alias to Cloudfront distribution`.
    - Pick a `region`.
    - Copy and paste the alias value from Begin into the `Choose Distribution` input. It should be a Cloudfront link like this: `d1poav0i4gjqri.cloudfront.net`
    - Click `Create record`.

## Conclusion

Now we're done! You can check to see if your domains are online with this [DNS Checker tool](https://dnschecker.org/).

Keep in mind that it make take a few hours for DNS to fully propagate so be patient.

### Starting over

Something not looking right? No sweat, DNS can be finicky. If you need to hit the reset button, just click Start over (or, if you've finished mapping your domain, Delete domain mapping).

Your app will then be restored to its original `yourappname.begin.app` URLs, and you'll be able to re-map your domain again.