@@ -979,29 +979,30 @@ def deploy_metric_filters_and_alarms(region: str, accounts: list, resource_prope
979
979
DRY_RUN_DATA ["KMSAliasCreate" ] = "DRY_RUN: Create SRA alarm KMS key alias"
980
980
else :
981
981
LOGGER .info (f"Found SRA alarm KMS key: { alarm_key_id } " )
982
- # Add KMS resource records to sra state table
983
- add_state_table_record (
984
- "kms" ,
985
- "implemented" ,
986
- "alarms sns kms key" ,
987
- "key" ,
988
- f"arn:aws:kms:{ region } :{ acct } :key/{ alarm_key_id } " ,
989
- acct ,
990
- region ,
991
- alarm_key_id ,
992
- alarm_key_id ,
993
- )
994
- add_state_table_record (
995
- "kms" ,
996
- "implemented" ,
997
- "alarms sns kms alias" ,
998
- "alias" ,
999
- f"arn:aws:kms:{ region } :{ acct } :alias/{ ALARM_SNS_KEY_ALIAS } " ,
1000
- acct ,
1001
- region ,
1002
- ALARM_SNS_KEY_ALIAS ,
1003
- alarm_key_id ,
1004
- )
982
+ if DRY_RUN is False :
983
+ # Add KMS resource records to sra state table
984
+ add_state_table_record (
985
+ "kms" ,
986
+ "implemented" ,
987
+ "alarms sns kms key" ,
988
+ "key" ,
989
+ f"arn:aws:kms:{ region } :{ acct } :key/{ alarm_key_id } " ,
990
+ acct ,
991
+ region ,
992
+ alarm_key_id ,
993
+ alarm_key_id ,
994
+ )
995
+ add_state_table_record (
996
+ "kms" ,
997
+ "implemented" ,
998
+ "alarms sns kms alias" ,
999
+ "alias" ,
1000
+ f"arn:aws:kms:{ region } :{ acct } :alias/{ ALARM_SNS_KEY_ALIAS } " ,
1001
+ acct ,
1002
+ region ,
1003
+ ALARM_SNS_KEY_ALIAS ,
1004
+ alarm_key_id ,
1005
+ )
1005
1006
1006
1007
# 4b) SNS topics for alarms
1007
1008
sns .SNS_CLIENT = sts .assume_role (acct , sts .CONFIGURATION_ROLE , "sns" , region )
@@ -1048,9 +1049,10 @@ def deploy_metric_filters_and_alarms(region: str, accounts: list, resource_prope
1048
1049
LOGGER .info (f"{ SOLUTION_NAME } -alarms SNS topic already exists." )
1049
1050
alarm_topic_arn = topic_search
1050
1051
# add SNS state table record
1051
- add_state_table_record (
1052
- "sns" , "implemented" , "sns topic for alarms" , "topic" , alarm_topic_arn , acct , region , f"{ SOLUTION_NAME } -alarms"
1053
- )
1052
+ if DRY_RUN is False :
1053
+ add_state_table_record (
1054
+ "sns" , "implemented" , "sns topic for alarms" , "topic" , alarm_topic_arn , acct , region , f"{ SOLUTION_NAME } -alarms"
1055
+ )
1054
1056
1055
1057
# 4c) Cloudwatch metric filters and alarms
1056
1058
if DRY_RUN is False :
@@ -1141,7 +1143,8 @@ def deploy_central_cloudwatch_observability(event: dict) -> None: # noqa: CCR00
1141
1143
oam_sink_arn = search_oam_sink [1 ]
1142
1144
LOGGER .info (f"CloudWatch observability access manager sink found: { oam_sink_arn } " )
1143
1145
# add OAM sink state table record
1144
- add_state_table_record ("oam" , "implemented" , "oam sink" , "sink" , oam_sink_arn , ssm_params .SRA_SECURITY_ACCT , sts .HOME_REGION , "oam_sink" )
1146
+ if DRY_RUN is False :
1147
+ add_state_table_record ("oam" , "implemented" , "oam sink" , "sink" , oam_sink_arn , ssm_params .SRA_SECURITY_ACCT , sts .HOME_REGION , "oam_sink" )
1145
1148
1146
1149
# 5b) OAM Sink policy in security account
1147
1150
cloudwatch .SINK_POLICY = CLOUDWATCH_OAM_SINK_POLICY ["sra-oam-sink-policy" ]
@@ -1225,16 +1228,17 @@ def deploy_central_cloudwatch_observability(event: dict) -> None: # noqa: CCR00
1225
1228
)
1226
1229
xacct_role_arn = search_iam_role [1 ]
1227
1230
# add cross account role state table record
1228
- add_state_table_record (
1229
- "iam" ,
1230
- "implemented" ,
1231
- "cross account sharing role" ,
1232
- "role" ,
1233
- xacct_role_arn ,
1234
- bedrock_account ,
1235
- iam .get_iam_global_region (),
1236
- cloudwatch .CROSS_ACCOUNT_ROLE_NAME ,
1237
- )
1231
+ if DRY_RUN is False :
1232
+ add_state_table_record (
1233
+ "iam" ,
1234
+ "implemented" ,
1235
+ "cross account sharing role" ,
1236
+ "role" ,
1237
+ xacct_role_arn ,
1238
+ bedrock_account ,
1239
+ iam .get_iam_global_region (),
1240
+ cloudwatch .CROSS_ACCOUNT_ROLE_NAME ,
1241
+ )
1238
1242
1239
1243
# 5d) Attach managed policies to CloudWatch-CrossAccountSharingRole IAM role
1240
1244
cross_account_policies = [
@@ -1287,7 +1291,8 @@ def deploy_central_cloudwatch_observability(event: dict) -> None: # noqa: CCR00
1287
1291
LOGGER .info (f"CloudWatch observability access manager link found in { bedrock_account } in { bedrock_region } " )
1288
1292
oam_link_arn = search_oam_link [1 ]
1289
1293
# add OAM link state table record
1290
- add_state_table_record ("oam" , "implemented" , "oam link" , "link" , oam_link_arn , bedrock_account , bedrock_region , "oam_link" )
1294
+ if DRY_RUN is False :
1295
+ add_state_table_record ("oam" , "implemented" , "oam link" , "link" , oam_link_arn , bedrock_account , bedrock_region , "oam_link" )
1291
1296
1292
1297
1293
1298
def deploy_cloudwatch_dashboard (event : dict ) -> None :
@@ -1333,16 +1338,17 @@ def deploy_cloudwatch_dashboard(event: dict) -> None:
1333
1338
DRY_RUN_DATA ["CloudWatchDashboardCreate" ] = "DRY_RUN: Create CloudWatch observability dashboard"
1334
1339
else :
1335
1340
LOGGER .info (f"Cloudwatch dashboard already exists: { search_dashboard [1 ]} " )
1336
- add_state_table_record (
1337
- "cloudwatch" ,
1338
- "implemented" ,
1339
- "cloudwatch dashboard" ,
1340
- "dashboard" ,
1341
- search_dashboard [1 ],
1342
- ssm_params .SRA_SECURITY_ACCT ,
1343
- sts .HOME_REGION ,
1344
- SOLUTION_NAME ,
1345
- )
1341
+ if DRY_RUN is False :
1342
+ add_state_table_record (
1343
+ "cloudwatch" ,
1344
+ "implemented" ,
1345
+ "cloudwatch dashboard" ,
1346
+ "dashboard" ,
1347
+ search_dashboard [1 ],
1348
+ ssm_params .SRA_SECURITY_ACCT ,
1349
+ sts .HOME_REGION ,
1350
+ SOLUTION_NAME ,
1351
+ )
1346
1352
1347
1353
1348
1354
def remove_cloudwatch_dashboard () -> None :
@@ -1399,21 +1405,24 @@ def create_event(event: dict, context: Any) -> str:
1399
1405
execution_role_arn = lambdas .get_lambda_execution_role (os .environ ["AWS_LAMBDA_FUNCTION_NAME" ])
1400
1406
execution_role_name = execution_role_arn .split ("/" )[- 1 ]
1401
1407
LOGGER .info (f"Adding state table record for lambda IAM execution role: { execution_role_arn } " )
1402
- add_state_table_record (
1403
- "iam" , "implemented" , "lambda execution role" , "role" , execution_role_arn , sts .MANAGEMENT_ACCOUNT , sts .HOME_REGION , execution_role_name
1404
- )
1405
- # add lambda function state table record
1406
- LOGGER .info (f"Adding state table record for lambda function: { context .invoked_function_arn } " )
1407
- LAMBDA_RECORD_ID = add_state_table_record (
1408
- "lambda" ,
1409
- "implemented" ,
1410
- "bedrock solution function" ,
1411
- "lambda" ,
1412
- context .invoked_function_arn ,
1413
- sts .MANAGEMENT_ACCOUNT ,
1414
- sts .HOME_REGION ,
1415
- context .function_name ,
1416
- )
1408
+ if DRY_RUN is False :
1409
+ # add lambda execution role state table record
1410
+ LOGGER .info (f"Adding state table record for lambda execution role: { execution_role_name } " )
1411
+ add_state_table_record (
1412
+ "iam" , "implemented" , "lambda execution role" , "role" , execution_role_arn , sts .MANAGEMENT_ACCOUNT , sts .HOME_REGION , execution_role_name
1413
+ )
1414
+ # add lambda function state table record
1415
+ LOGGER .info (f"Adding state table record for lambda function: { context .invoked_function_arn } " )
1416
+ LAMBDA_RECORD_ID = add_state_table_record (
1417
+ "lambda" ,
1418
+ "implemented" ,
1419
+ "bedrock solution function" ,
1420
+ "lambda" ,
1421
+ context .invoked_function_arn ,
1422
+ sts .MANAGEMENT_ACCOUNT ,
1423
+ sts .HOME_REGION ,
1424
+ context .function_name ,
1425
+ )
1417
1426
1418
1427
# 1) Stage config rule lambda code (global/home region)
1419
1428
deploy_stage_config_rule_lambda_code ()
@@ -1999,7 +2008,8 @@ def deploy_iam_role(account_id: str, rule_name: str) -> str: # noqa: CFQ001, CC
1999
2008
if role_arn is None :
2000
2009
role_arn = ""
2001
2010
# add IAM role state table record
2002
- add_state_table_record ("iam" , "implemented" , "role for config rule" , "role" , role_arn , account_id , "Global" , rule_name )
2011
+ if DRY_RUN is False :
2012
+ add_state_table_record ("iam" , "implemented" , "role for config rule" , "role" , role_arn , account_id , "Global" , rule_name )
2003
2013
2004
2014
iam .SRA_POLICY_DOCUMENTS ["sra-lambda-basic-execution" ]["Statement" ][0 ]["Resource" ] = iam .SRA_POLICY_DOCUMENTS [ # noqa: ECE001
2005
2015
"sra-lambda-basic-execution"
@@ -2028,9 +2038,10 @@ def deploy_iam_role(account_id: str, rule_name: str) -> str: # noqa: CFQ001, CC
2028
2038
else :
2029
2039
LOGGER .info (f"{ rule_name } -lamdba-basic-execution IAM policy already exists" )
2030
2040
# add IAM policy state table record
2031
- add_state_table_record (
2032
- "iam" , "implemented" , "policy for config rule role" , "policy" , policy_arn , account_id , "Global" , f"{ rule_name } -lamdba-basic-execution"
2033
- )
2041
+ if DRY_RUN is False :
2042
+ add_state_table_record (
2043
+ "iam" , "implemented" , "policy for config rule role" , "policy" , policy_arn , account_id , "Global" , f"{ rule_name } -lamdba-basic-execution"
2044
+ )
2034
2045
2035
2046
policy_arn2 = f"arn:{ sts .PARTITION } :iam::{ account_id } :policy/{ rule_name } "
2036
2047
iam_policy_search2 = iam .check_iam_policy_exists (policy_arn2 )
@@ -2047,7 +2058,8 @@ def deploy_iam_role(account_id: str, rule_name: str) -> str: # noqa: CFQ001, CC
2047
2058
else :
2048
2059
LOGGER .info (f"{ rule_name } IAM policy already exists" )
2049
2060
# add IAM policy state table record
2050
- add_state_table_record ("iam" , "implemented" , "policy for config rule" , "policy" , policy_arn2 , account_id , "Global" , rule_name )
2061
+ if DRY_RUN is False :
2062
+ add_state_table_record ("iam" , "implemented" , "policy for config rule" , "policy" , policy_arn2 , account_id , "Global" , rule_name )
2051
2063
2052
2064
policy_attach_search1 = iam .check_iam_policy_attached (rule_name , policy_arn )
2053
2065
if policy_attach_search1 is False :
@@ -2128,7 +2140,8 @@ def deploy_lambda_function(account_id: str, rule_name: str, role_arn: str, regio
2128
2140
LOGGER .info (f"{ rule_name } already exists in { account_id } . Search result: { lambda_function_search } " )
2129
2141
lambda_arn = lambda_function_search
2130
2142
# add Lambda state table record
2131
- add_state_table_record ("lambda" , "implemented" , "lambda for config rule" , "lambda" , lambda_arn , account_id , region , rule_name )
2143
+ if DRY_RUN is False :
2144
+ add_state_table_record ("lambda" , "implemented" , "lambda for config rule" , "lambda" , lambda_arn , account_id , region , rule_name )
2132
2145
2133
2146
return lambda_arn
2134
2147
@@ -2179,7 +2192,8 @@ def deploy_config_rule(account_id: str, rule_name: str, lambda_arn: str, region:
2179
2192
LOGGER .info (f"{ rule_name } config rule already exists." )
2180
2193
config_rule_arn = config_rule_search [1 ]["ConfigRules" ][0 ]["ConfigRuleArn" ]
2181
2194
# add Config rule state table record
2182
- add_state_table_record ("config" , "implemented" , "config rule" , "rule" , config_rule_arn , account_id , region , rule_name )
2195
+ if DRY_RUN is False :
2196
+ add_state_table_record ("config" , "implemented" , "config rule" , "rule" , config_rule_arn , account_id , region , rule_name )
2183
2197
2184
2198
2185
2199
def deploy_metric_filter (
@@ -2211,7 +2225,8 @@ def deploy_metric_filter(
2211
2225
else :
2212
2226
LOGGER .info (f"Metric filter { filter_name } already exists." )
2213
2227
# add metric filter state table record
2214
- add_state_table_record ("cloudwatch" , "implemented" , "log metric filter" , "filter" , metric_filter_arn , acct , region , filter_name )
2228
+ if DRY_RUN is False :
2229
+ add_state_table_record ("cloudwatch" , "implemented" , "log metric filter" , "filter" , metric_filter_arn , acct , region , filter_name )
2215
2230
2216
2231
2217
2232
def deploy_metric_alarm ( # noqa: CFQ002
@@ -2279,7 +2294,8 @@ def deploy_metric_alarm( # noqa: CFQ002
2279
2294
else :
2280
2295
LOGGER .info (f"Metric alarm { alarm_name } already exists." )
2281
2296
# add metric alarm state table record
2282
- add_state_table_record ("cloudwatch" , "implemented" , "cloudwatch metric alarm" , "alarm" , alarm_arn , acct , region , alarm_name )
2297
+ if DRY_RUN is False :
2298
+ add_state_table_record ("cloudwatch" , "implemented" , "cloudwatch metric alarm" , "alarm" , alarm_arn , acct , region , alarm_name )
2283
2299
2284
2300
2285
2301
def lambda_handler (event : dict , context : Any ) -> dict : # noqa: CCR001
0 commit comments