【问题标题】:boto3: How to get the IP addresses of CloudFormation stack instances?boto3:如何获取 CloudFormation 堆栈实例的 IP 地址?
【发布时间】:2016-08-31 20:35:42
【问题描述】:

我需要发现 AWS CloudFormation 堆栈中每个主机的私有 IP 地址。

CloudFormation API(请参阅http://boto3.readthedocs.io/en/latest/reference/services/cloudformation.html)似乎没有任何直接支持提取给定堆栈 ID 的节点。有没有可能?

【问题讨论】:

    标签: amazon-web-services boto amazon-cloudformation boto3


    【解决方案1】:

    是的,这是可能的,但并不简单。

    1. 在您的帐户/个人资料中获取堆栈列表
    2. 循环遍历列表并创建堆栈名称列表
    3. 获取每个堆栈(名称)的堆栈资源(describe_stack_resources)
    4. 找到resource['LogicalResourceId'] == 'Ec2Instance'的资源
    5. 从该资源中获取 inst_id
    6. 获得 inst_id 后,您可以使用 boto3.resource('ec2') 获取其属性,包括 private_ip

    我已经对此进行了编码并定期使用它。如果调用过于频繁,AWS 可能会限制您的 CF 调用。

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2018-10-01
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 2019-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多