Search code examples
amazon-web-servicesssl-certificatesubdomainaws-application-load-balancer

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?)


Solution

  • 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)