Skip to content

Commit 003fbf0

Browse files
committed
alarms sns topic state record
1 parent cbff778 commit 003fbf0

File tree

1 file changed

+37
-0
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# TODO(liamschn): deal with linting failures in pipeline
3232
# TODO(liamschn): deal with typechecking/mypy
3333
# TODO(liamschn): check for unused parameters
34+
# TODO(liamschn): need to ensure DRY_RUN is false for any dynamodb state table record insertions
3435

3536
from typing import TYPE_CHECKING, Sequence # , Union, Literal, Optional
3637

@@ -834,6 +835,42 @@ def deploy_metric_filters_and_alarms(region, accounts, resource_properties):
834835
else:
835836
LOGGER.info(f"{SOLUTION_NAME}-alarms SNS topic already exists.")
836837
SRA_ALARM_TOPIC_ARN = topic_search
838+
if DRY_RUN is False:
839+
# SNS state table record
840+
# TODO(liamschn): move dynamodb resource to the dynamo class object/module
841+
dynamodb_resource = sts.assume_role_resource(ssm_params.SRA_SECURITY_ACCT, sts.CONFIGURATION_ROLE, "dynamodb", sts.HOME_REGION)
842+
843+
item_found, find_result = dynamodb.find_item(
844+
STATE_TABLE,
845+
dynamodb_resource,
846+
SOLUTION_NAME,
847+
{
848+
"arn": SRA_ALARM_TOPIC_ARN,
849+
},
850+
)
851+
if item_found is False:
852+
sns_record_id, sns_date_time = dynamodb.insert_item(STATE_TABLE, dynamodb_resource, SOLUTION_NAME)
853+
else:
854+
sns_record_id = find_result["record_id"]
855+
856+
dynamodb.update_item(
857+
STATE_TABLE,
858+
dynamodb_resource,
859+
SOLUTION_NAME,
860+
sns_record_id,
861+
{
862+
"aws_service": "sns",
863+
"component_state": "implemented",
864+
"account": acct,
865+
"description": "alarms sns topic",
866+
"component_region": region,
867+
"component_type": "topic",
868+
"component_name": f"{SOLUTION_NAME}-alarms",
869+
"arn": SRA_ALARM_TOPIC_ARN,
870+
"date_time": dynamodb.get_date_time(),
871+
},
872+
)
873+
837874

838875
# 4c) Cloudwatch metric filters and alarms
839876
# arn:aws:logs:<region>:<account-id>:metric-filter:<filter-name>

0 commit comments

Comments
 (0)