@@ -446,6 +446,8 @@ def deploy_state_table():
446446
447447 if DRY_RUN is False :
448448 LOGGER .info ("Live run: creating the state table..." )
449+ # TODO(liamschn): move dynamodb client and resource to the dynamo class object/module
450+ # TODO(liamschn): move the deploy state table function to the dynamo class object/module?
449451 dynamodb_client = sts .assume_role (ssm_params .SRA_SECURITY_ACCT , sts .CONFIGURATION_ROLE , "dynamodb" , sts .HOME_REGION )
450452
451453 if dynamodb .table_exists (STATE_TABLE , dynamodb_client ) is False :
@@ -522,7 +524,7 @@ def deploy_sns_configuration_topics(context):
522524 topic_arn = sns .create_sns_topic (f"{ SOLUTION_NAME } -configuration" , SOLUTION_NAME )
523525 LIVE_RUN_DATA ["SNSCreate" ] = f"Created { SOLUTION_NAME } -configuration SNS topic"
524526 CFN_RESPONSE_DATA ["deployment_info" ]["action_count" ] += 1
525- CFN_RESPONSE_DATA ["deployment_info" ]["resources_deployed" ] += 1
527+ CFN_RESPONSE_DATA ["deployment_info" ]["resources_deployed" ] += 1
526528
527529 LOGGER .info (f"Creating SNS topic policy permissions for { topic_arn } on { context .function_name } lambda function" )
528530 # TODO(liamschn): search for permissions on lambda before adding the policy
@@ -551,6 +553,41 @@ def deploy_sns_configuration_topics(context):
551553 else :
552554 LOGGER .info (f"{ SOLUTION_NAME } -configuration SNS topic already exists." )
553555 topic_arn = topic_search
556+ # SNS State table record:
557+ # TODO(liamschn): move dynamodb resource to the dynamo class object/module
558+ dynamodb_resource = sts .assume_role_resource (ssm_params .SRA_SECURITY_ACCT , sts .CONFIGURATION_ROLE , "dynamodb" , sts .HOME_REGION )
559+ item_found , find_result = dynamodb .find_item (
560+ STATE_TABLE ,
561+ dynamodb_resource ,
562+ SOLUTION_NAME ,
563+ {
564+ "arn" : topic_arn ,
565+ },
566+ )
567+ if item_found is False :
568+ sns_record_id , sns_date_time = dynamodb .insert_item (STATE_TABLE , dynamodb_resource , SOLUTION_NAME )
569+ else :
570+ sns_record_id = find_result ["record_id" ]
571+
572+ dynamodb .update_item (
573+ STATE_TABLE ,
574+ dynamodb_resource ,
575+ SOLUTION_NAME ,
576+ sns_record_id ,
577+ {
578+ "aws_service" : "sns" ,
579+ "component_state" : "implemented" ,
580+ "account" : ACCOUNT ,
581+ "description" : "configuration topic" ,
582+ "component_region" : sts .HOME_REGION ,
583+ "component_type" : "topic" ,
584+ "component_name" : f"{ SOLUTION_NAME } -configuration" ,
585+ "arn" : topic_arn ,
586+ "date_time" : dynamodb .get_date_time (),
587+ },
588+ )
589+
590+
554591 return topic_arn
555592
556593def deploy_config_rules (region , accounts , resource_properties ):
@@ -967,21 +1004,6 @@ def create_event(event, context):
9671004
9681005 # 3, 4, and 5 handled by SNS
9691006 accounts , regions = get_accounts_and_regions (event ["ResourceProperties" ])
970- # TODO(liamschn): Move get regions and accounts into its own function (confirm working)
971- # if "SRA-BEDROCK-ACCOUNTS" in event["ResourceProperties"]:
972- # LOGGER.info("SRA-BEDROCK-ACCOUNTS found in event ResourceProperties")
973- # accounts = json.loads(event["ResourceProperties"]["SRA-BEDROCK-ACCOUNTS"])
974- # LOGGER.info(f"SRA-BEDROCK-ACCOUNTS: {accounts}")
975- # else:
976- # LOGGER.info("SRA-BEDROCK-ACCOUNTS not found in event ResourceProperties; setting to None")
977- # accounts = []
978- # if "SRA-BEDROCK-REGIONS" in event["ResourceProperties"]:
979- # LOGGER.info("SRA-BEDROCK-REGIONS found in event ResourceProperties")
980- # regions = json.loads(event["ResourceProperties"]["SRA-BEDROCK-REGIONS"])
981- # LOGGER.info(f"SRA-BEDROCK-REGIONS: {regions}")
982- # else:
983- # LOGGER.info("SRA-BEDROCK-REGIONS not found in event ResourceProperties; setting to None")
984- # regions = []
9851007
9861008 # 3) Deploy config rules (regional)
9871009 # deploy_config_rules(event)
0 commit comments