Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AWS ALB to have subdomains pointing to different target groups

Right now I have a domain (example.com) that I have hosted on Google Domains, but uses Amazon's Route 53 DNS servers, and I've created a hosted zone & registered an SSL certificate for free with ACM. So I got it to take requests for example.com and forwards them to a target group (EC2 instance).

I'd like to expand this into:

  • staging.example.com
  • prod.example.com

where each has its own target group it points to.

Is this possible with an ALB? How would I encode this into the load balancer's routing rules?

(Also: would I have to re-verify the SSL cert for the subdomains?)

like image 666
lollercoaster Avatar asked Jan 25 '23 17:01

lollercoaster


2 Answers

You route each subdomain to different target group using Listener Rules

enter image description here

When you add a Listener Rule, set a condition for Host header and select the subdomain you want to use e.g. staging.example.com and select Forward to as your target group.

enter image description here

Regarding SSL, you won't need to create a new certificate as long as you have the certificate for *.example.com attached to the listener (see View/Edit certificates)

like image 66
ubi Avatar answered Jan 29 '23 12:01

ubi


Yes, it is possible. Just create another recordset in your hosted zone (presumably the same way you did it for example.com) for staging and for prod. As for the certificate issue, you will need a wildcard certificate if you want to use the same certificate for all 3 hosts (example.com, staging.example.com and prod.example.com).

like image 33
Ashaman Kingpin Avatar answered Jan 29 '23 13:01

Ashaman Kingpin