I’m in the process of migrating some workloads to Amazon ECS Container Service and I found a blocker that is preventing me from moving forward.
Ideally, containerized apps running on ECS should be stateless so that they can run in any cluster instance and scale out. But the reality is that I have some apps that are dependent on EBS data volumes. As far as I know, these volumes have to be manually attached to a particular cluster instance and ECS apps should be placed in that instance to be able access its data, so I need to have some way to control where these end up running.
As an example, let’s say we have a cluster of 3 EC2 instances managed by Amazon ECS.
- instance1
- instance2
- instance3
Then we have 2 containerized apps:
- app1, which is stateless
- app2, which depends on an EBS volume
app1 can run in any instance of the cluster, no problem.
For app2, let’s say we attach and mount the EBS volume in instance2.
Now, the question is: can I put a restriction when defining or launching app2 to be placed only in instance2 so that it can have access to the EBS volume?
Thanks so much in advance!
EDITED:
I’ve reading a bit further and I found a way to do it in Amazon’s documentation. There is a note in the document “Using Data Volumes in Tasks” that says:
Important
Amazon ECS does not sync your data volumes across container instances. Tasks that use persistent data volumes can be placed on any container instance in your cluster that has available capacity. If your tasks require persistent data volumes after stopping and restarting, you should always specify the same container instance at task launch time with the AWS CLI start-task command.
So, looking at the start-task command on the CLI I found out that it is exactly what I was looking for:
start-task
Starts a new task from the specified task definition on the specified container instance or instances. To use the default Amazon ECS scheduler to place your task, use run-task instead.
It has two required parameters that are the task definition you want to launch and the container instance IDs (up to 10) on which the task should run.
So calling the command would look something like this:
aws ecs start-task --task-definition “hello-world:1” --container-instances “1c66549d-b41c-4439-dd43-c2e1c9a2cc2a”
I tried it and it worked perfectly.
Currently, this looks like the only way to do it, since the AWS web UI does not provide a field to specify the container instances when launching a task.
I hope it can be useful somebody.