Я думаю, что вы можете сделать это с помощью ECS API.Например,
import boto3
CLUSTER = 'YOUR_CLUSTER_ID'
EC2 = 'YOUR_EC2_ID'
ecs = boto3.client('ecs')
ci_list_response = ecs.list_container_instances(
cluster=CLUSTER
)
# Describe those ARNs
ci_descriptions_response = ecs.describe_container_instances(
cluster=CLUSTER,
containerInstances=ci_list_response['containerInstanceArns']
)
# Look for a container instance with the given EC2 instance ID
# Then for want of something better to do, print all the details
for ci in ci_descriptions_response['containerInstances']:
if ci['ec2InstanceId'] == EC2:
print(ci)
Редактировать: Мне пришло в голову, что вас больше интересует, какие задачи выполняются в этом экземпляре, которые вы также можете получить.
import boto3
CLUSTER = 'YOUR_CLUSTER_ID'
EC2 = 'YOUR_EC2_ID'
ecs = boto3.client('ecs')
ci_list_response = ecs.list_container_instances(
cluster=CLUSTER
)
# Describe those ARNs
ci_descriptions_response = ecs.describe_container_instances(
cluster=CLUSTER,
containerInstances=ci_list_response['containerInstanceArns']
)
# Look for a container instance with the given EC2 instance ID
# Then for want of something better to do, print all the details
for ci in ci_descriptions_response['containerInstances']:
if ci['ec2InstanceId'] == EC2:
# List tasks on this container instance
t_list_response = ecs.list_tasks(
cluster=CLUSTER,
containerInstance=ci['containerInstanceArn']
)
# Describe tasks
t_descriptions_response = ecs.describe_tasks(
cluster=CLUSTER,
tasks=t_list_response['taskArns']
)
print(t_descriptions_response)