Adding a subdomain backed by an alb to route 53


I have mapped a godaddy domain to an AWS instance by creating and ALB and adding it to Route53. I have purchased an SSL from Godaddy and installed the same on ALB.

I am now trying to add a subdomain to the same configuration wherein the sub-domain will be mapped to another EC2 instance. I am new to this setup and the way I understand is, there are two ways I can do that:
1. Create a record in the hosted zone and map it to the subdomain.
2. Create a hosted zone and add it as an NS record to the hosted zone of the parent domain.
Now I want to know if I can:
1. Attach a load balancer to the other instance and add it as a subdomain. If yes, then how?
2. Add the other instance to the existing load balancer and configure routing for it then add a record in the hosted zone with the load balancer as an alias.

The instances in the discussion would act as a frontend and a backend respectively.
Help is appreciated. Thanks in advance.!

Upvotes: 0

Views: 1426

Answers (1)

Vlad
Vlad

Reputation: 425

In Route 53 records should be added for your hosted zone (parent domain):

example.com.            A   ALIAS your-aws-alb-alias
subdomain.example.com.  A   ALIAS your-aws-alb-alias

You don't need to create another hosted zone for subdomain.

Then you can add instances to ALB through Target Groups. See this tutorial.

Create target groups for backend and frontend, for example Backend-Target and Frontend-Target. Then you need to create host-based rules in ALB. For example:

IF Host is subdomain.example.com THEN Forward to Backend-Target: 1 (100%)
IF Host is example.com THEN Forward to Frontend-Target: 1 (100%)

The order of the rules matters. Rules in ALB are processed from top to bottom.

Upvotes: 3

Related Questions