使用boto3列出100多个堆栈 [英] Listing more than 100 stacks using boto3

查看:54
本文介绍了使用boto3列出100多个堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要列出所有处于CREATE_COMPLETE状态的堆栈。在我们的AWS账户中,我们有超过400个这样的堆栈。为此,我们编写了以下代码:

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

但这仅列出了前100个堆栈。我们想知道如何获得所有筹码吗?我们正在使用python boto3库。

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.

推荐答案

我使用分页进行了这项工作。我写的代码如下:

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

可以打印所有451个我们需要。

That printed all the 451 stacks that we needed.

这篇关于使用boto3列出100多个堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆