Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the describe_stack Output attribute

i have created a stack in cloudformatin and wants to get the output. My code is:

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

Returns an object

<boto.cloudformation.stack.StackSummary object at 0x1901d10>
like image 595
Suresh Sala Avatar asked Jan 16 '14 05:01

Suresh Sala


People also ask

How do you reference output from another CloudFormation stack?

To create a cross-stack reference, use the export field to flag the value of a resource output for export. Then, use the Fn::ImportValue intrinsic function to import the value in any stack within the same AWS Region and account. AWS CloudFormation identifies exported values by the names specified in the template.

What are outputs in CloudFormation?

The optional Outputs section declares output values that you can import into other stacks (to create cross-stack references), return in response (to describe stack calls), or view on the AWS CloudFormation console. For example, you can output the S3 bucket name for a stack to make the bucket easier to find.

How do I export a value from CloudFormation template?

To export a stack's output value, use the Export field in the Output section of the stack's template. To import those values, use the Fn::ImportValue function in the template for the other stacks. For a walkthrough and sample templates, see Walkthrough: Refer to resource outputs in another AWS CloudFormation stack.

How do you describe a stack?

A stack is a conceptual structure consisting of a set of homogeneous elements and is based on the principle of last in first out (LIFO). It is a commonly used abstract data type with two major operations, namely push and pop.


1 Answers

The call to describe_stacks should return a list of Stack objects, not a single StackSummary object. Let's just walk through a complete example to avoid confusion.

First, do something like this:

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

At this point the variable stack is a Stack object. The outputs of the stack are available as the outputs attribute of stack. This attribute will contain a list of Output objects which, in turn, have a key, value, and description attribute. So, this would print all of the outputs:

for output in stack.outputs:
    print('%s=%s (%s)' % (output.key, output.value, output.description))
like image 196
garnaat Avatar answered Sep 21 '22 22:09

garnaat