python - 如何读取describe_stack输出属性

标签 python amazon-web-services stack boto aws-cloudformation

我已经在cloudformatin中创建了一个堆栈并希望获得输出。 我的代码是:

c = a.describe_stacks('Stack_id') 
print c

返回一个对象

<boto.cloudformation.stack.StackSummary object at 0x1901d10>

最佳答案

describe_stacks的调用应该返回Stack对象的列表,而不是单个StackSummary对象。让我们看一个完整的示例以避免混淆。

首先,执行以下操作:

import boto.cloudformation
conn = boto.cloudformation.connect_to_region('us-west-2')  # or your favorite region
stacks = conn.describe_stacks('MyStackID')
if len(stacks) == 1:
    stack = stacks[0]
else:
    # Raise an exception or something because your stack isn't there

此时变量stack是一个Stack对象。堆栈的输出可作为 stackoutputs 属性使用。此属性将包含一个 Output 对象列表,这些对象依次具有 keyvaluedescription属性。因此,这将打印所有输出:

for output in stack.outputs:
    print('%s=%s (%s)' % (output.key, output.value, output.description))

关于python - 如何读取describe_stack输出属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21154126/

相关文章:

python - 设置 EB CLI - 错误 nonetype get_frozen_credentials

python - Scipy 似乎不可能在 Beanstalk 上工作

c - 使用堆栈计算表达式 (C)

c - 如何从 `push %ebp`获取汇编指令的相对偏移量

arrays - 在 Forth 中设置数组元素的问题

python - 在 Python2.7 中将列表转换为字典的最佳方法是什么

python - 尝试从 Web 表中提取数据时出现 Selenium 错误

amazon-web-services - 如何使用匿名用户将 aws CLI 配置为 s3 cp

python - 如何自定义Folium中的LayerControl?

python - 如何在python列表中的特定索引处插入元素