Search code examples
amazon-web-servicesdocker-composeamazon-ecs

a service in ecs fails to find another service within the same network


I have a very simple docker-compose for locust (python package for load testing). It starts a 'master' service and a 'slave' service. Everything works perfectly locally but when I deploy it to AWS ECS a 'slave' can't find a master.

services:
  my-master:
    image: chapkovski/locust
    ports:
      - "80:80"
    env_file:
      - .env
    environment:
      LOCUST_MODE: master

  my-slave:
    image: chapkovski/locust
    env_file:
      - .env
    environment:
      LOCUST_MODE: slave
      LOCUST_MASTER_HOST: my-master

So apparently I need to refer from my-slave service not to my-master when I am on ECS. What's wrong here?


Solution

  • Everything works perfectly locally but when I deploy it to AWS ECS a 'slave' can't find a master.

    I assume that slave needs to access master both must be in the same task definition to access like this or you can explore service discovery?

      "links": [
          "master"
        ]
    

    links

    Type: string array
    
    Required: no
    

    The link parameter allows containers to communicate with each other without the need for port mappings. Only supported if the network mode of a task definition is set to bridge. The name:internalName construct is analogous to name:alias in Docker links.

    Note

    This parameter is not supported for Windows containers or tasks using the awsvpc network mode.

    Important

    Containers that are collocated on a single container instance may be able to communicate with each other without requiring links or host port mappings. Network isolation is achieved on the container instance using security groups and VPC settings.

    "links": ["name:internalName", ...]
    

    container_definition_network