【发布时间】:2018-11-16 23:51:21
【问题描述】:
我正在使用 AWS Cloudformation 创建一个堆栈,并希望从 describe_stacks() 返回的字典中获取“PublicIP”字段的值。 下面的原理图代码可以完成这项工作,但它对字典结构的变化没有弹性:
#!/usr/bin/python
import sys
import boto3
import rest_client
if len(sys.argv) < 2:
print "Bad usage: missing stack name"
exit(1)
session = boto3.Session(profile_name='profile name')
client = session.client('cloudformation')
response = client.describe_stacks(StackName=sys.argv[1])
try:
ip = response['Stacks'][0]['Outputs'][1]['OutputValue']
print "Extracted instance IP address ({0})".format(ip)
except IndexError:
print "IP address not found"
exit(1)
我可以使用更具体的 API 来直接获取此字段吗?
【问题讨论】:
标签: python aws-sdk amazon-cloudformation