我已经在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
对象。堆栈的输出可作为 stack
的 outputs
属性使用。此属性将包含一个 Output
对象列表,这些对象依次具有 key
、value
和 description
属性。因此,这将打印所有输出:
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/