首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从boto3 cloudformation describe_stack接口中只获取OutputKey?

如何从boto3 cloudformation describe_stack接口中只获取OutputKey?
EN

Stack Overflow用户
提问于 2020-08-07 13:54:39
回答 1查看 137关注 0票数 1

需要帮助!我正在尝试使用boto3部署CloudFormation堆栈。在cloudformation模板中,使用下面的输出参数代码。当我运行describe_stack时,它向我显示了堆栈和所有属性的完整描述。如何从下面的OutputKeys中仅获取其中的一部分?例如,如果我只想要PublicDNS或PublicIP怎么办?

代码语言:javascript
复制
Outputs:
  InstanceId:
    Description: InstanceId of the newly created EC2 instance
    Value: !Ref EC2Instance
  AZ:
    Description: Availability Zone of the newly created EC2 instance
    Value: !GetAtt 
      - EC2Instance
      - AvailabilityZone
  PublicDNS:
    Description: Public DNSName of the newly created EC2 instance
    Value: !GetAtt 
      - EC2Instance
      - PublicDnsName
  PublicIP:
    Description: Public IP address of the newly created EC2 instance
    Value: !GetAtt 
      - EC2Instance
      - PublicIp
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-07 14:07:38

Stack的帮助下,您可以执行以下操作(PublicDNS示例

代码语言:javascript
复制
import boto3

session = boto3.Session(aws_access_key_id='', aws_secret_access_key=''...) 

cloudformation = session.resource('cloudformation')

stack = cloudformation.Stack('<your-stack-name>')

print(stack.outputs)

public_dns = ''

for output in stack.outputs:
    if output['OutputKey'] == 'PublicDNS':
        public_dns = output['OutputValue']
        break

print(public_dns)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63295987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档