Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two ECS tasks connectivity in one EC2 Host

I have 2 ECS Services running with EC2 launch type and bridge networking mode. each service is having 1 task and both tasks are running on same EC2 container host.

on the Same ECS host, API container in 1st task is trying to communicate DB container in 2nd task by host name and port number( ex: http://abc-def:5000). what are the ways to achieve this ?

like image 652
Shah Avatar asked Nov 07 '25 16:11

Shah


1 Answers

Your options are:

  1. Put everything in a single task definition. Then you can use the link attribute to enable container A to communicate with container B like so B:port. Notice that link does not support circular relations meaning if A can talk with B, B will not be able to do that as well.

  2. Switch to network mode host. This way you can communicate with localhost.

  3. Proper service discovery with a tool like Consul or AWS ECS Service Discovery. I have no experience with the latter. See here.

  4. Put your tasks behind ALB and use this load balancer to communicate between tasks.

like image 185
trallnag Avatar answered Nov 10 '25 11:11

trallnag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!