需要帮助!我正在尝试使用boto3部署CloudFormation堆栈。在cloudformation模板中,使用下面的输出参数代码。当我运行describe_stack时,它向我显示了堆栈和所有属性的完整描述。如何从下面的OutputKeys中仅获取其中的一部分?例如,如果我只想要PublicDNS或PublicIP怎么办?
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发布于 2020-08-07 14:07:38
在Stack的帮助下,您可以执行以下操作(PublicDNS示例
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)https://stackoverflow.com/questions/63295987
复制相似问题