DEV Community

Arun Kumar for AWS Community Builders

Posted on

Orphaned CloudFormation Stacks — HouseKeeping


  • There could be some stacks missed out during teardown process due to some issues and this might leave those stacks orphaned.
  • Also when App teams create a new stack without deleting their previous stack, this will leave the previous stack orphaned.


  • List out all the stacks based on the state in the corresponding account using below python script. Filter the suspecting orphaned stacks from the list.
# Function: EvaluateOrphanedStacks
# Purpose: List out stacks based on the state and accounts
import boto3
import json
from datetime import datetime
from datetime import date
def list_stacks():
paginator = cfn_client.get_paginator('list_stacks')
response_iterator = paginator.paginate(
for page in response_iterator:
for stack in page['StackSummaries']:
if __name__ == '__main__':
Enter fullscreen mode Exit fullscreen mode

Its ALWAYS recommended and good practice to reduce the orphaned stacks and unwanted resources !

Top comments (0)