Listing more than 100 stacks using boto3

强颜欢笑 提交于 2019-12-07 05:06:11

问题


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:

stack_session = session.client('cloudformation')
list_stacks = stack_session.list_stacks(StackStatusFilter=['CREATE_COMPLETE'])

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.


回答1:


I got this working using pagination. The code I wrote is below:

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']

That printed all the 451 stacks that we needed.



来源:https://stackoverflow.com/questions/39228551/listing-more-than-100-stacks-using-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!