|
31 | 31 | # TODO(liamschn): deal with linting failures in pipeline |
32 | 32 | # TODO(liamschn): deal with typechecking/mypy |
33 | 33 | # TODO(liamschn): check for unused parameters |
| 34 | +# TODO(liamschn): need to ensure DRY_RUN is false for any dynamodb state table record insertions |
34 | 35 |
|
35 | 36 | from typing import TYPE_CHECKING, Sequence # , Union, Literal, Optional |
36 | 37 |
|
@@ -834,6 +835,42 @@ def deploy_metric_filters_and_alarms(region, accounts, resource_properties): |
834 | 835 | else: |
835 | 836 | LOGGER.info(f"{SOLUTION_NAME}-alarms SNS topic already exists.") |
836 | 837 | 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 | + |
837 | 874 |
|
838 | 875 | # 4c) Cloudwatch metric filters and alarms |
839 | 876 | # arn:aws:logs:<region>:<account-id>:metric-filter:<filter-name> |
|
0 commit comments