Skip to content

Reach ECS service on unmapped port

0

Hello, Is there a way to reach a service on an unmapped port. Context: I have 2 ECS service - 1 is running on EC2 and 1 on Fargate. Both are running in the same VPC in private subnets. The routes in VPC are in place. The security groups of both service permits each inbound traffic from each other on -1 (all ports) and permits inbound traffic from the CIDR of the VPC (entire CIDR). All egress traffic is allowed to 0.0.0.0/0 (all). no NACL restriction are in place. Is it possible to reach from the service1 (the one that runs on EC2) to the service 2 (Fargate) without mapping a specific port on the one in Fargate? I mean with something like "port_mappings = []" My service 1 (from EC2) must communicate with the service 2 (on Fargate) but I don't know I must map all specific ports that is used. Do I?

2 Answers
0

In the scenario you've described, it is not possible to reach the Fargate service (service 2) from the EC2-based service (service 1) without mapping specific ports on the Fargate service.

When using Amazon ECS, especially with Fargate, you need to explicitly define the ports that your container exposes and that you want to make accessible. This is done through port mappings in the task definition.

The reason for this is that Fargate tasks run in their own isolated network environment. Without port mappings, there's no way for other services to know which ports are available or how to route traffic to the correct container and process within the Fargate task.

You will need to map all the specific ports that your Fargate service uses and needs to expose. This is a crucial part of defining how your service can be accessed. Each port that needs to be reachable should be included in the port mappings of your task definition.

If you're unsure about all the ports your application uses, you may need to review your application's configuration or code to identify all the ports it listens on or tries to use for communication.

Remember, even though your security groups allow all inbound traffic between the services, the Fargate networking model still requires explicit port mappings to route traffic correctly to your containers.

If you need more flexible communication between your services without managing specific port mappings, you might want to consider using Amazon ECS Service Connect or AWS Cloud Map for service discovery. These solutions can simplify service-to-service communication within your ECS environment.
Sources
Interconnect Amazon ECS services - Amazon Elastic Container Service
Amazon ECS Service Connect configuration overview - Amazon Elastic Container Service

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Ok. Thank you, but even with the service_connect I still need port mapping.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.