@@ -1982,14 +1982,34 @@ def is_resource_orphaned(check_stack_name: str) -> bool:
19821982 except Exception as e :
19831983 logger .warning (f"Failed to cleanup IAM custom policies: { e } " )
19841984
1985- # Clean up BDA blueprints associated with this stack
1985+ # Clean up BDA projects and blueprints associated with this stack
19861986 try :
19871987 bda_client = boto3 .client (
19881988 "bedrock-data-automation" , region_name = self .region
19891989 )
1990+
1991+ # Delete BDA projects first (blueprints are referenced by projects)
1992+ try :
1993+ for p in bda_client .list_data_automation_projects ().get (
1994+ "projects" , []
1995+ ):
1996+ if p .get ("projectName" , "" ).startswith (f"{ stack_name } -" ):
1997+ try :
1998+ bda_client .delete_data_automation_project (
1999+ projectArn = p ["projectArn" ]
2000+ )
2001+ logger .info (f"Deleted BDA project: { p ['projectName' ]} " )
2002+ except Exception as proj_error :
2003+ logger .warning (
2004+ f"Failed to delete BDA project { p ['projectName' ]} : { proj_error } "
2005+ )
2006+ except Exception as e :
2007+ logger .warning (f"Failed to cleanup BDA projects: { e } " )
2008+
2009+ # Delete blueprints (versions first, then base)
19902010 paginator = bda_client .get_paginator ("list_blueprints" )
19912011 deleted_count = 0
1992- for page in paginator .paginate (blueprintStage = "LIVE" ):
2012+ for page in paginator .paginate (blueprintStageFilter = "LIVE" ):
19932013 for blueprint in page .get ("blueprints" , []):
19942014 bp_name = blueprint .get ("blueprintName" , "" )
19952015 bp_arn = blueprint .get ("blueprintArn" , "" )
@@ -1998,6 +2018,12 @@ def is_resource_orphaned(check_stack_name: str) -> bool:
19982018 continue
19992019 if bp_name .startswith (f"{ stack_name } -" ):
20002020 try :
2021+ try :
2022+ bda_client .delete_blueprint (
2023+ blueprintArn = bp_arn , blueprintVersion = "1"
2024+ )
2025+ except Exception :
2026+ pass
20012027 bda_client .delete_blueprint (blueprintArn = bp_arn )
20022028 deleted_count += 1
20032029 logger .info (f"Deleted BDA blueprint: { bp_name } " )
0 commit comments