'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 1:[1]
Yes, there is a similar feature in AWS ECS called Container Dependency.
https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html
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.
Solution 2:[2]
If your containers are on separated tasks, I suggest the following way to work around:
For example you got container-A in task-A and container-B in task-B, and you need to run container-B when container-A is available.
- Expose a health check of container-A. For example: :8081/health
- Create container-C in task-B. This container will try to ping to container-A via health check until success.
- container-B will depend on container-C to start.
Just the idea. Thank you for reading.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abhinaya |
Solution 2 | Minh |