Skip to content

Instantly share code, notes, and snippets.

@fabidick22
Last active November 6, 2019 20:53
Show Gist options
  • Save fabidick22/90877a74f6fb4ab0beae4225a53f1983 to your computer and use it in GitHub Desktop.
Save fabidick22/90877a74f6fb4ab0beae4225a53f1983 to your computer and use it in GitHub Desktop.
Get all stack (CloudFormation) from Boto3 (Python)
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