Search code examples
amazon-web-servicesdockercontainersamazon-ecsaws-fargate

Depends on Fargate ECS


I have container A this container holds my broker service that delivers messages and creates a socket that my other services connect to and then send messages to.

I have an issue where container A has to be running before containers B and C or they are unable to connect to the socket.

In ECS / Fargate is it possible to tell containers B and C to restart if container A goes down or if container A is restarted to tell B and C to redeploy so the application is spun up again and it can successfully connect to the socket.

In docker-compose I can use depends_on within the setup, Is there something similar for ECS / Fargate?

I have tried adding

   "dependsOn": [
        {
            "containerName" : "containerA",
            "condition" : "HEALTHY"
        }
    ]

To my task definition but it complains it can't find the container. My containers are all in separate task definitions in separate services.


Solution

  • Yes, there is a similar feature in AWS ECS called Container Dependency.

    https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html

    https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_dependson

    The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed.