Orphaned CloudFormation Stacks — HouseKeeping | DevsDay.ru

IT-блоги Orphaned CloudFormation Stacks — HouseKeeping

dev.to 11 июня 2021 г.


Scenario

  • 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.

Solution

  • 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
cfn_client=boto3.client('cloudformation')
def list_stacks():
paginator = cfn_client.get_paginator('list_stacks')
response_iterator = paginator.paginate(
StackStatusFilter=[
'CREATE_IN_PROGRESS',
'CREATE_FAILED',
'CREATE_COMPLETE',
'ROLLBACK_IN_PROGRESS',
'ROLLBACK_FAILED',
'ROLLBACK_COMPLETE',
'DELETE_IN_PROGRESS',
'DELETE_FAILED',
'UPDATE_IN_PROGRESS',
'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_COMPLETE',
'UPDATE_ROLLBACK_IN_PROGRESS',
'UPDATE_ROLLBACK_FAILED',
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_ROLLBACK_COMPLETE',
'REVIEW_IN_PROGRESS',
'IMPORT_IN_PROGRESS',
'IMPORT_COMPLETE',
'IMPORT_ROLLBACK_IN_PROGRESS',
'IMPORT_ROLLBACK_FAILED',
'IMPORT_ROLLBACK_COMPLETE'
]
)
for page in response_iterator:
for stack in page['StackSummaries']:
print(stack['StackName'])
if __name__ == '__main__':
list_stacks()

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

Источник: dev.to

Наш сайт является информационным посредником. Сообщить о нарушении авторских прав.

aws cloudformation housekeeping cost