Search code examples
amazon-web-servicesamazon-ec2amazon-ecsamazon-elbaws-fargate

How can i enable communication between two tasks running on different AWS ECS Clusters


I have two fargate tasks running in two different clusters, the first one is running on port 3000 and can receive requests from anyone, the second one is running on port 8080 and can be accessed only by the first one. Both are in the same Security Group and VPC.

I created an inbound rule to allow public access for the first one, then I tried to create other inbound rule to enable the access for the second through security group ingress. But when the first service tries to access the second, I receive an Timeout Error.

When I allow the public access to the second service, the communication works properly, but I cannot allow it to run forever.

Each service has a load balancer configured, but I've already tried (unsuccessfully) to access the service by its task's public IP.

Anyone has any idea what I am doing wrong?? The inbound rules for the security group can be checked in this image


Solution

  • If the first service tries to access the second service by the second service's public IP, then the traffic will go out to the Internet and back, which will destroy the network traffic's association with the origin security group.

    To keep the traffic inside the VPC, and to make sure the security group rules apply as intended, the first service needs to connect to the second service via the second service's private IP.

    If you are using a load balancer for the second service, then it needs to be an internal load balancer, not an external load balancer.