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

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

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

返回一个对象

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

【问题讨论】:

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


【解决方案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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-27
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    相关资源
    最近更新 更多