0

I'm wondering if there is a way to determine which EC2 instance in a Cluster a Task will run on?

I have a Cluster of EC2 instances in Amazon ECS, where I'm running multiple Services on this cluster.

When I update a Service with a New Task, sometimes the task runs on an EC2 instance without a task running, but other times it runs on an EC2 instance with a task already running upon it. I would like to keep which task runs on each EC2 instance consistent as I need to know the IP address to map requests to the appropriate EC2 instance.

Is there a way to solve this issue?

fuzzi
  • 1,967
  • 9
  • 46
  • 90

2 Answers2

0

ECS is not going to assign your task to a known host, it will always pick one from the pool. If you need to access the task you need to bind a DNS entry to it, you can then access the service that way.

Bill Leeper
  • 683
  • 1
  • 10
  • 20
  • thanks for the information. Do you have a reference for binding a DNS entry to the task or server? – fuzzi Sep 11 '18 at 17:42
  • I have come across Service Discovery which sets a DNS record on the Service. However, these DNS records can only be resolved by ec2 instances within the cluster. I would want to be able to resolve these externally from the cluster. (Reference: https://medium.com/containers-on-aws/how-to-setup-service-discovery-in-elastic-container-service-3d18479959e6) – fuzzi Sep 12 '18 at 01:06
  • AWS is always changing, so I am not fully up on the mechanics, but you should be able to use Route56 to set the DNS entry to point at your container. If you have setup the container and your VPC for public access that DNS entry should work for public consumption. – Bill Leeper Sep 12 '18 at 14:57
0

A rather "naive" answer, as it doesn't exactly resolve the whole dynamic DNS topic of ECS clusters, but it does give you the EC2 Instance ID the current container is running on:

aws ecs describe-container-instances --container-instances YOUR_CONTAINER_ID --cluster YOUR_CLUSTER_NAME --query 'containerInstances[*].ec2InstanceId'

you can get the list of containers in the cluster with aws ecs list-container-instances --cluster YOUR_CLUSTER_NAME

Nune Isabekyan
  • 531
  • 2
  • 4