【问题标题】:Get autoscaling name from ecs ec2 instances从 ecs ec2 实例获取自动缩放名称
【发布时间】:2019-01-23 06:23:12
【问题描述】:

我有一个 ECS 集群,我想停止这些实例,它可能是自动缩放的,也可能不是……所以我开始创建这样的脚本。

import boto3

CLUSTER='BBB'
ec2 = boto3.client('ec2') 
ecs = boto3.client('ecs')

ci_list_response = ecs.list_container_instances(
    cluster=CLUSTER )

ci_descriptions_response = ecs.describe_container_instances(
    cluster=CLUSTER,
    containerInstances=ci_list_response['containerInstanceArns'] )

for ci in ci_descriptions_response['containerInstances']:   
    print(ci['ec2InstanceId'])

我能够获取 ec2-instance id 的列表,但难以获取这些实例的自动缩放信息。如果有解决此问题的方法,请分享您的想法。

【问题讨论】:

    标签: boto3 autoscaling amazon-ecs


    【解决方案1】:

    ec2_client.describe_instances(instanceId)

    在响应中查找 requesterId,它应该会为您提供所需的信息

    https://boto3.readthedocs.io/en/latest/reference/services/ec2.html

    【讨论】:

    • 谢谢,但收到以下消息..请检查此链接..让我知道........docs.google.com/document/d/…
    • 看起来您的请求格式不正确,该函数需要一个实例 ID 列表
    • 我应该怎么做才能获得这些信息?你能指导我吗?
    猜你喜欢
    • 1970-01-01
    • 2017-11-15
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 2016-03-09
    相关资源
    最近更新 更多