How to find another container on the same ECS cluster by hostname?

This question feels too obvious to not already have an answer but all of my google searches are coming up with nothing.

In docker (docker-compose) you can easily get the IP of another container by hostname. If you have explicitly created and assigned a network this just works out of the box. So a container foo can connect to another container bar simply by looking up the hostname "bar".

I'm trying to achieve something similar in AWS ECS to allow a container from one service to talk to a container in another service. The ECS cluster has multiple hosts so I don't think I can just specify bridge type networking.

Note that the protocol I need this for is not HTTP so an application load balancer is already out of the question.

Is there a recommended way to let one container discover another on the same cluster via hostname?


Solution 1:

Amazon ECS service discovery is integrated in ECS:

This makes it possible for an ECS service to automatically register itself with a predictable and friendly DNS name in Amazon Route 53. As your services scale up or down in response to load or container health, the Route 53 hosted zone is kept up to date, allowing other services to lookup where they need to make connections based on the state of each service.

The linked blog post contains in deep explanation and sample code.