DEV Community

Arswaw
Arswaw

Posted on

Create a subdomain in Amazon Route53 in 2 minutes

In this guide, I will show you to create a subdomain in Amazon Route53.

An example of how this is useful could be adding api onto your existing domain. You can redirect "api.yourwebsite.com" to an EC2 instance or a load balancer for instance.

You will need an AWS account for this.
You will start and end this guide in Route53.

  1. If you haven't already, create a hosted zone for your original domain. (example.com)
  2. Create a new hosted zone for your subdomain by clicking on "Create Hosted Zone" and entering the following:

Domain Name: api.example.com (or whatever you want your subdomain to be)
Comment: This can be anything
Type: Public Hosted Zone

  1. Click "Create"
  2. Click into your hosted zone, and select the record set with type "NS"
  3. Copy the nameservers in the "value" box on the right.
  4. Return to your original hosted zone. (example.com)
  5. Click "Create Record Set" and enter the following:

Name: api.example.com (or whatever your subdomain hosted zone is called)
Type: NS - Name Server
Value: Paste in those nameservers you copied.

  1. Click "Create"
  2. Return to the hosted zone for your subdomain and click "Create Record Set"
  3. You can redirect your subdomain to anything you want now. You can use an "A" record with a blank "Name" field and enter in an IP address. You can click "Yes" next to an alias and then click in the "Alias Target" box to select which AWS service to resolve to. When you are done click "Create"

In 1-2 minutes, open up a new tab and enter your new subdomain. It should resolve. If it does not, check that you completed the steps correctly. If it still does not resolve, leave a comment below the post.

I hope this helps anyone who was looking for an easy way to create a subdomain in Route53.

Thank you.

Top comments (20)

Collapse
 
abhishekagarwal3003 profile image
abhishekagarwal-3003

Hi..
This is my scenario..
I've a domain say "example.com" which is hosted externally i.e., not on Route53, and now I want to create a sub-domain say "test.example.com" in Route53 which would be used to reach the site from my client network(data center) over DirectConnect, and the url would be say "api1.test.example.com" and "api2.test.example.com", both pointing to the same server in the AWS VPC. So may I know how should I proceed with the Route53 configuration? Do I also need to use Route53 resolver endpoint in this case?

Collapse
 
arswaw profile image
Arswaw

Yes. Using a private hosted zone, you should expect to use R53 Resolver.

Collapse
 
abhishekagarwal3003 profile image
abhishekagarwal-3003

Hi Arswaw,

Thanks for the reply. What if I use a public hosted zone?

Thread Thread
 
arswaw profile image
Arswaw

According to the AWS docs:

"You can also use a Route 53 private hosted zone to route traffic within one or more VPCs that you create with the Amazon VPC service."

This implies that you need a private hosted zone to route to VPC.

Check out this forum response from an AWS employee specifying how you can use the public and private hosted zones together.

Does this help?

Thread Thread
 
abhishekagarwal3003 profile image
abhishekagarwal-3003

Hi Arswaw,

Yes, it helps, it's Private Hosted Zone which I need to use in this case. So is it mandatory to use a Route53 resolver in between or I can map api1.test.example.com and api2.test.example.com directly to my server's private ip on the remote DNS server?

Asking this because I tried both i.e., mapping directly to server's ip as well as mapping to resolver inbound endpoint ip, and what I see is that the former works but the latter doesn't. So any idea where am I going wrong?

Thread Thread
 
arswaw profile image
Arswaw

As convenient as that would be, I would use Resolver. It will take additional setup. However, it will take less setup than the alternative which is to build your own DNS servers.

If you successfully accomplish your mission with the tools you have available to you, would you let me know? I could edit the article to discuss what Route53 can do regarding hybrid clouds.

Should you need additional help, I will be checking this website regularly.

Thread Thread
 
abhishekagarwal3003 profile image
abhishekagarwal-3003

Sure, thanks for your help.

Collapse
 
shamabbas profile image
sham

Scenario is like:
I have a domain and also sub-domain and all the records are created within hosted zone (Route53) already. (DevOps guy created)
Now need to create another subdomain without choosing a different server (IP).
I have tried creating record set within the hosted zone using A and the same IP as for the other sub-domain, didn't work. Also tried A and ELB in Alias Target but that didn't work either.

What could be done in such case?

Collapse
 
thebazshah profile image
Muhammad Shahbaz

If you are directing all of your subdomains to same IP address, you'll have to configure your web server to handle your subdomains differently. For example yourdomain.com, sub1.yourdomain.com and sub2.yourdomain.com will be directed to same IP address but yourdomain.com will run code at path /var/www/html, sub1 will run application at path /var/www/sub1, and sub2 will run code at /var/www/sub2.
It's not Route53, it's your web server that needs to be configured. If you're using Nginx, following article can help you.
dev.to/on_stash/configure-nginx-to...

Collapse
 
arswaw profile image
Arswaw

You're saying that you want to create a second subdomain that resolves to the same IP address as the first?

Collapse
 
niyazpoyilan profile image
Niyaz Poyilan

currently the domain "example.com" is hosted on AWS Route 53. Now I want to create a sub-domain "shop.example.com" , but it would have different nameserver (Not AWS). Will it be possible to do so

Collapse
 
arswaw profile image
Arswaw

There shouldn't be any reason why not. I will look at this when I return to my computer and give you a definitive answer.

Collapse
 
niyazpoyilan profile image
Niyaz Poyilan

Hey, Any update?

Thread Thread
 
arswaw profile image
Arswaw

Hey, apologies for forgetting about this. I will work on this today.

Collapse
 
niyazpoyilan profile image
Niyaz Poyilan

Thank you. Will be looking forward to hearing from you

Collapse
 
brianacox1964 profile image
Brian Anthony Cox • Edited

Hi, thanks for your blog... like so many others I'm also struggling with setting up a www subdomain.

Before we do our main website, I'm practicing with foreskinconsulting.co.uk ... which works nicely on S3 and Route53. The problem is that whether I do, and there seems to be different approaches, I can't get www. foreskinconsulting .co .uk to work... I get getting 404 NoSuchBucket. I've been through and followed your instructions, I hope, to the letter....

Collapse
 
arswaw profile image
Arswaw • Edited

You need to create called yourdomain.co.uk and then have it redirect to yourdomain.com in the static site options. If you need further help on this, I can provide them.

Collapse
 
nasabayat profile image
Naser Bayat

Hi Arswaw,

Thanks for your help.

Collapse
 
seaguy profile image
William Laing

Thank you, Arswaw, very helpful!

Collapse
 
cankaraman profile image
Can Karaman

Hi,
You can also create sub-domains in the same hosted zone for simple projects:
docs.aws.amazon.com/Route53/latest...