如何读取描述堆栈输出属性

2024-05-08 02:32:52 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

返回一个对象

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

Tags: 对象代码idobjectstack堆栈atboto
1条回答
网友
1楼 · 发布于 2024-05-08 02:32:52

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

相关问题 更多 >