如何读取 describe_stack 输出属性

Posted

技术标签:

【中文标题】如何读取 describe_stack 输出属性【英文标题】:How to read the describe_stack Output attribute 【发布时间】:2014-02-04 21:47:30 【问题描述】:

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

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

返回一个对象

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

【问题讨论】:

Returning the outputs from a CloudFormation template with Boto?的可能重复 【参考方案1】:

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))

【讨论】:

以上是关于如何读取 describe_stack 输出属性的主要内容,如果未能解决你的问题,请参考以下文章