Idiomatic way to get IP addresses of group of containers in ECS?

I'm building an internal proxy service on AWS where a user can

  • send a request to a server
  • that server will send the request to one of several proxy containers in an ECS cluster

I'm not sure what's the best way to get the IP addresses of the proxy containers in the ECS cluster.

I could manually list the IPs once every N seconds and check if new containers have joined the ECS cluster, but I wonder if there's a better way?


Solution 1:

You can listen for CloudWatch Events or AWS EventBridge Events related to container spin-up / tear-down. You can probably trigger a lambda for each event that can then do something, like add the container IP to a wherever it needs to be registered.

Alternatively you can use ECS Service Discovery that uses DNS to keep a list of active containers.

And finally you can get the containers to register themselves when they spin up. That's also an option, though a bit more DIY'ish.

Hope that helps :)