How can I allow the tasks in my Amazon ECS services to communicate with each other?
Last updated: 2019-07-15
How can I allow the tasks in my Amazon Elastic Container Service (Amazon ECS) services to communicate with each other?
You can use service discovery to enable your Amazon ECS services to communicate with each other. Service discovery applies to tasks that meet the following conditions:
- A task from one Amazon ECS service can connect with any other task in another Amazon ECS service.
- Tasks can connect to each other directly (without going through load balancers).
- Task IP addresses (and optionally, ports) in the Amazon ECS service are updated whenever tasks are started or stopped.
Note: Amazon ECS services can use AWS Cloud Map as an optional service discovery mechanism. For tasks running in AWS Cloud Map, an Amazon ECS service with service discovery maintains a set of DNS records. Service discovery supports the following DNS record types: A and SRV. DNS records are automatically added or removed as tasks start or stop in the Amazon ECS service. If a task or an app needs to connect to your Amazon ECS service, then that task or app can locate an existing task from the DNS record. Amazon ECS supports private DNS records (resolvable from within a VPC) using AWS Cloud Map.
Before you create a new service with service discovery, consider the following:
- You must enable service discovery during the creation of an Amazon ECS service.
- You must create a new service. An existing Amazon ECS service can't be updated with service discovery.
- If you use A records for service discovery, you can create a new task definition using awsvpc network mode.
- Be sure to meet the additional requirements of awsvpc tasks.
- A or SRV records are supported for tasks that use the awsvpc network mode (including all AWS Fargate tasks).
- SRV records are supported for tasks that use bridge and host network modes. The none network mode isn't supported.
To allow your tasks to communicate with each other, complete the following steps: