Listing more than 100 stacks using boto3
<p>We need to list all the stacks that are in CREATE_COMPLETE state. In our AWS account we have >400 such stacks. We have the following code written for this:</p>

<pre><code>stack_session = session.client('cloudformation')
list_stacks = stack_session.list_stacks(StackStatusFilter=['CREATE_COMPLETE'])
</code></pre>

<p>However this lists only the first 100 stacks. We want to know how we can get all the stacks? We are using the python boto3 library.</p>

<p>I got this working using pagination. The code I wrote is below:</p>

<pre><code>stack_session = session.client('cloudformation')
paginator = stack_session.get_paginator('list_stacks')
response_iterator = paginator.paginate(StackStatusFilter=['CREATE_COMPLETE'])
for page in response_iterator:
    stack = page['StackSummaries']
    for output in stack:
        print output['StackName']
</code></pre>

<p>That printed all the 451 stacks that we needed.</p>

python boto3 cloudformation