Skip to content

Commit 21878ad

Browse files
committed
handle blank rule/metric regions/accounts
1 parent 0f798d3 commit 21878ad

File tree

1 file changed

+20
-10
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+20
-10
lines changed

aws_sra_examples/solutions/genai/bedrock_org/lambda/src/app.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ def deploy_config_rules(region, accounts, resource_properties):
459459
rule_deploy, rule_accounts, rule_regions, rule_input_params = get_rule_params(rule_name, resource_properties)
460460
rule_name = rule_name.lower()
461461
LOGGER.info(f"Create operation: examining {rule_name} resources...")
462+
if rule_regions:
463+
LOGGER.info(f"{rule_name} regions: {rule_regions}")
464+
if region not in rule_regions:
465+
LOGGER.info(f"{rule_name} does not apply to {region}; skipping...")
466+
continue
462467

463468
for acct in accounts:
464469

@@ -468,10 +473,11 @@ def deploy_config_rules(region, accounts, resource_properties):
468473
# rule_deploy, rule_accounts, rule_regions, rule_input_params = get_rule_params(rule_name, event)
469474
if rule_deploy is False:
470475
continue
471-
if acct not in rule_accounts:
472-
continue
473-
if region not in rule_regions:
474-
continue
476+
if rule_accounts:
477+
LOGGER.info(f"{rule_name} accounts: {rule_accounts}")
478+
if acct not in rule_accounts:
479+
LOGGER.info(f"{rule_name} does not apply to {acct}; skipping...")
480+
continue
475481
# for acct in rule_accounts:
476482
if DRY_RUN is False:
477483
# 3a) Deploy IAM role for custom config rule lambda
@@ -524,9 +530,11 @@ def deploy_metric_filters_and_alarms(region, accounts, resource_properties):
524530
if filter_deploy is False:
525531
LOGGER.info(f"{filter} filter not requested (deploy set to false). Skipping...")
526532
continue
527-
if region not in filter_regions:
528-
LOGGER.info(f"{filter} filter not requested for {region}. Skipping...")
529-
continue
533+
if filter_regions:
534+
LOGGER.info(f"{filter} filter regions: {filter_regions}")
535+
if region not in filter_regions:
536+
LOGGER.info(f"{filter} filter not requested for {region}. Skipping...")
537+
continue
530538
LOGGER.info(f"Raw filter pattern: {CLOUDWATCH_METRIC_FILTERS[filter]}")
531539
if "BUCKET_NAME_PLACEHOLDER" in CLOUDWATCH_METRIC_FILTERS[filter]:
532540
LOGGER.info(f"{filter} filter parameter: 'BUCKET_NAME_PLACEHOLDER' found. Updating with bucket info...")
@@ -541,9 +549,11 @@ def deploy_metric_filters_and_alarms(region, accounts, resource_properties):
541549
# for region in regions:
542550
# 4a) Deploy KMS keys
543551
# 4ai) KMS key for SNS topic used by CloudWatch alarms
544-
if acct not in filter_accounts:
545-
LOGGER.info(f"{filter} filter not requested for {acct}. Skipping...")
546-
continue
552+
if filter_accounts:
553+
LOGGER.info(f"filter_accounts: {filter_accounts}")
554+
if acct not in filter_accounts:
555+
LOGGER.info(f"{filter} filter not requested for {acct}. Skipping...")
556+
continue
547557
kms.KMS_CLIENT = sts.assume_role(acct, sts.CONFIGURATION_ROLE, "kms", region)
548558
search_alarm_kms_key, alarm_key_alias, alarm_key_id = kms.check_alias_exists(kms.KMS_CLIENT, f"alias/{ALARM_SNS_KEY_ALIAS}")
549559
if search_alarm_kms_key is False:

0 commit comments

Comments
 (0)