Search code examples
amazon-web-servicesdnsamazon-ecselastic-load-balancer

AWS ECS handling DNS subdomains across multiple instances


So I am trying to get my AWS setup working with DNS.

I have 2 instances (currently). I have 4 task definitions. 3 of these need to run on port 80/443, however all on separate subdomains.

ECS container diagram

Currently if I stop/start a task, it can end up on either of my instances. This causes issues with the subdomain DNS potentially being pointed in the wrong places.

I imagine I need to setup some kind of load balancer to point the DNS at, but unsure how to get that to route through to the correct tasks.

Load balancer diagram

So my questions:

  1. Do I need a single load balancer, or one per 'task / subdomain'?
  2. How do I handle the ports to go from a set source port, to one of any number of destination ports (if I end up having multiple containers running the same task)
  3. Am I over complicating this massively, or is there a simpler way to achieve this?

Solution

    1. Do I need a single load balancer, or one per 'task / subdomain'?

    You can have a single application load balancer and three target groups for Api, Site and Web App. Then you can do a rule base routing in the load balancer listener as shown in the following screenshot.

    enter image description here

    Ref: http://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html

    You can then map your domains www.domain.com and app.domain.com to the load balancer

    1. How do I handle the ports to go from a set source port, to one of any number of destination ports (if I end up having multiple containers running the same task)

    When you create services for your task definitions in ECS you can configure load balancing using the target groups you created.

    Ref: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-service.html (Check on "Configuring Your Service to Use a Load Balancer")