Last active
November 6, 2019 20:53
-
-
Save fabidick22/90877a74f6fb4ab0beae4225a53f1983 to your computer and use it in GitHub Desktop.
Get all stack (CloudFormation) from Boto3 (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 as b3 | |
cf_b3 = b3.client("cloudformation", region_name="us-east-1") | |
def get_all_stacks(): | |
""" | |
Function to get all stacks. | |
:return: (dict) Dict object | |
""" | |
stacks = cf_b3.list_stacks() | |
while stacks.get("NextToken", None): | |
new_stack = cf_b3.list_stacks(**{"NextToken": stacks.get("NextToken")}) | |
stacks["StackSummaries"] = stacks.get("StackSummaries", []) + new_stack.get("StackSummaries", []) | |
if new_stack.get("NextToken", None): | |
stacks["NextToken"] = new_stack["NextToken"] | |
else: | |
del stacks["NextToken"] | |
return stacks | |
print(get_all_stacks()["StackSummaries"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment