@@ -598,34 +598,6 @@ def create_event(event, context):
598598 DRY_RUN_DATA [f"{ filter } _CloudWatch" ] = "DRY_RUN: Filter deploy parameter is 'false'; Skip CloudWatch metric filter deployment"
599599
600600 # 5) Central CloudWatch Observability
601- # TODO(liamschn): determine if we need the CloudWatch-CrossAccountListAccountsRole (needed for "Enable account selector"?).
602- # TRUST
603- # {
604- # "Version": "2012-10-17",
605- # "Statement": [
606- # {
607- # "Effect": "Allow",
608- # "Principal": {
609- # "AWS": "arn:aws:iam::533267199951:root"
610- # },
611- # "Action": "sts:AssumeRole"
612- # }
613- # ]
614- # }
615- # PERMISSIONS
616- # {
617- # "Version": "2012-10-17",
618- # "Statement": [
619- # {
620- # "Action": [
621- # "organizations:ListAccounts",
622- # "organizations:ListAccountsForParent"
623- # ],
624- # "Resource": "*",
625- # "Effect": "Allow"
626- # }
627- # ]
628- # }
629601 central_observability_params = json .loads (event ["ResourceProperties" ]["SRA-BEDROCK-CENTRAL-OBSERVABILITY" ])
630602 # TODO(liamschn): create a parameter to choose to deploy central observability or not: deploy_central_observability = true/false
631603 # 5a) OAM Sink in security account
@@ -768,6 +740,7 @@ def create_event(event, context):
768740 DRY_RUN_DATA ["CloudWatchDashboardCreate" ] = "DRY_RUN: Create CloudWatch observability dashboard"
769741 else :
770742 LOGGER .info (f"Cloudwatch dashboard already exists: { search_dashboard [1 ]} " )
743+ # TODO(liamschn): check content of dashboard to ensure it is the latest content and update as needed
771744 # check_dashboard = cloudwatch.compare_dashboard(search_dashboard[1], cloudwatch_dashboard)
772745 # if check_dashboard is False:
773746 # if DRY_RUN is False:
@@ -841,6 +814,23 @@ def delete_event(event, context):
841814 LOGGER .info (f"{ SOLUTION_NAME } -configuration SNS topic does not exist." )
842815
843816 # 2) Delete Central CloudWatch Observability
817+ # 2a) Delete cloudwatch dashboard
818+ cloudwatch .CLOUDWATCH_CLIENT = sts .assume_role (SECURITY_ACCOUNT , sts .CONFIGURATION_ROLE , "cloudwatch" , sts .HOME_REGION )
819+ search_dashboard = cloudwatch .find_dashboard (SOLUTION_NAME )
820+ if search_dashboard [0 ] is False :
821+ LOGGER .info ("CloudWatch observability dashboard not found" )
822+ else :
823+ if DRY_RUN is False :
824+ LOGGER .info ("Deleting CloudWatch observability dashboard" )
825+ LIVE_RUN_DATA ["CloudWatchDashboardDelete" ] = "Deleted CloudWatch observability dashboard"
826+ cloudwatch .delete_dashboard (SOLUTION_NAME )
827+ CFN_RESPONSE_DATA ["deployment_info" ]["action_count" ] += 1
828+ CFN_RESPONSE_DATA ["deployment_info" ]["resources_deployed" ] -= 1
829+ else :
830+ LOGGER .info ("DRY_RUN: Deleting CloudWatch observability dashboard" )
831+
832+
833+
844834 central_observability_params = json .loads (event ["ResourceProperties" ]["SRA-BEDROCK-CENTRAL-OBSERVABILITY" ])
845835
846836 cloudwatch .CWOAM_CLIENT = sts .assume_role (SECURITY_ACCOUNT , sts .CONFIGURATION_ROLE , "oam" , sts .HOME_REGION )
@@ -852,8 +842,9 @@ def delete_event(event, context):
852842 oam_sink_arn = "Error:Sink:Arn:Not:Found"
853843
854844 # Add management account to the bedrock accounts list
855- central_observability_params ["bedrock_accounts" ].append (sts .MANAGEMENT_ACCOUNT )
856- for bedrock_account in central_observability_params ["bedrock_accounts" ]:
845+ bedrock_and_mgmt_accounts = copy .deepcopy (central_observability_params ["bedrock_accounts" ])
846+ bedrock_and_mgmt_accounts .append (sts .MANAGEMENT_ACCOUNT )
847+ for bedrock_account in bedrock_and_mgmt_accounts :
857848 for bedrock_region in central_observability_params ["regions" ]:
858849 # 2a) OAM link in bedrock account
859850 cloudwatch .CWOAM_CLIENT = sts .assume_role (bedrock_account , sts .CONFIGURATION_ROLE , "oam" , bedrock_region )
0 commit comments