@@ -10,125 +10,125 @@ module "search-patient-details-gateway" {
1010 origin = contains ([" prod" ], terraform. workspace ) ? " 'https://${ var . domain } '" : " 'https://${ terraform . workspace } .${ var . domain } '"
1111}
1212
13- module "search_patient_alarm" {
14- source = " ./modules/lambda_alarms"
15- lambda_function_name = module. search-patient-details-lambda . function_name
16- lambda_timeout = module. search-patient-details-lambda . timeout
17- lambda_name = " search_patient_details_handler"
18- namespace = " AWS/Lambda"
19- alarm_actions = [module . search_patient_alarm_topic . arn ]
20- ok_actions = [module . search_patient_alarm_topic . arn ]
21- depends_on = [module . search-patient-details-lambda , module . search_patient_alarm_topic ]
22- }
23- #
24- # resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_low" {
25- # alarm_name = "search_patient_error_count_low"
26- # alarm_description = "Triggers when search patient lambda error count is between 1 and 3 within 2mins"
27- # comparison_operator = "GreaterThanThreshold"
28- # threshold = 0
29- # evaluation_periods = 1
30- # alarm_actions = [module.search_patient_alarm_topic.arn]
31- # ok_actions = [module.search_patient_alarm_topic.arn]
32- # tags = {
33- # is_kpi = "true"
34- # alarm_group = module.search-patient-details-lambda.function_name
35- # alarm_metric = "Errors"
36- # severity = "low"
37- # }
38- # metric_query {
39- # id = "error"
40- # label = "error count for search patient, low if between 1 and 3"
41- # return_data = true
42- # expression = "IF(m1 >= 1 AND m1 <= 3, 1, 0)"
43- # }
44- #
45- # metric_query {
46- # id = "m1"
47- #
48- # metric {
49- # metric_name = "Errors"
50- # namespace = "AWS/Lambda"
51- # period = 120
52- # stat = "Sum"
53- # dimensions = {
54- # FunctionName = module.search-patient-details-lambda.function_name
55- # }
56- # }
57- # }
58- # }
59- #
60- # resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_medium" {
61- # alarm_name = "search_patient_error_count_medium"
62- # alarm_description = "Triggers when search patient lambda error count is between 4 and 6 within 2mins"
63- # comparison_operator = "GreaterThanThreshold"
64- # threshold = 0
65- # evaluation_periods = 1
66- # alarm_actions = [module.search_patient_alarm_topic.arn]
67- # ok_actions = [module.search_patient_alarm_topic.arn]
68- # tags = {
69- # is_kpi = "true"
70- # alarm_group = module.search-patient-details-lambda.function_name
71- # alarm_metric = "Errors"
72- # severity = "medium"
73- # }
74- # metric_query {
75- # id = "error"
76- # label = "error count for search patient, medium if between 4 and 6"
77- # return_data = true
78- # expression = "IF(m1 >= 4 AND m1 <= 6, 1, 0)"
79- # }
80- #
81- # metric_query {
82- # id = "m1"
83- #
84- # metric {
85- # metric_name = "Errors"
86- # namespace = "AWS/Lambda"
87- # period = 120
88- # stat = "Sum"
89- # dimensions = {
90- # FunctionName = module.search-patient-details-lambda.function_name
91- # }
92- # }
93- # }
94- # }
95- #
96- # resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_high" {
97- # alarm_name = "search_patient_error_count_high"
98- # alarm_description = "Triggers when search patient lambda error count is 7 or above"
99- # comparison_operator = "GreaterThanThreshold"
100- # threshold = 0
101- # evaluation_periods = 1
102- # alarm_actions = [module.search_patient_alarm_topic.arn]
103- # ok_actions = [module.search_patient_alarm_topic.arn]
104- # tags = {
105- # is_kpi = "true"
106- # alarm_group = module.search-patient-details-lambda.function_name
107- # alarm_metric = "Errors"
108- # severity = "high"
109- # }
110- # metric_query {
111- # id = "error"
112- # label = "error count for search patient, high if 7 or above"
113- # return_data = true
114- # expression = "IF(m1 >= 7, 1, 0)"
115- # }
116- #
117- # metric_query {
118- # id = "m1"
119- #
120- # metric {
121- # metric_name = "Errors"
122- # namespace = "AWS/Lambda"
123- # period = 120
124- # stat = "Sum"
125- # dimensions = {
126- # FunctionName = module.search-patient-details-lambda.function_name
127- # }
128- # }
129- # }
13+ # module "search_patient_alarm" {
14+ # source = "./modules/lambda_alarms"
15+ # lambda_function_name = module.search-patient-details-lambda.function_name
16+ # lambda_timeout = module.search-patient-details-lambda.timeout
17+ # lambda_name = "search_patient_details_handler"
18+ # namespace = "AWS/Lambda"
19+ # alarm_actions = [module.search_patient_alarm_topic.arn]
20+ # ok_actions = [module.search_patient_alarm_topic.arn]
21+ # depends_on = [module.search-patient-details-lambda, module.search_patient_alarm_topic]
13022# }
13123
24+ resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_low" {
25+ alarm_name = " search_patient_error_count_low"
26+ alarm_description = " Triggers when search patient lambda error count is between 1 and 3 within 2mins"
27+ comparison_operator = " GreaterThanThreshold"
28+ threshold = 0
29+ evaluation_periods = 1
30+ alarm_actions = [module . search_patient_alarm_topic . arn ]
31+ ok_actions = [module . search_patient_alarm_topic . arn ]
32+ tags = {
33+ is_kpi = " true"
34+ alarm_group = module.search- patient- details- lambda.function_name
35+ alarm_metric = " Errors"
36+ severity = " low"
37+ }
38+ metric_query {
39+ id = " error"
40+ label = " error count for search patient, low if between 1 and 3"
41+ return_data = true
42+ expression = " IF(m1 >= 1 AND m1 <= 3, 1, 0)"
43+ }
44+
45+ metric_query {
46+ id = " m1"
47+
48+ metric {
49+ metric_name = " Errors"
50+ namespace = " AWS/Lambda"
51+ period = 120
52+ stat = " Sum"
53+ dimensions = {
54+ FunctionName = module.search- patient- details- lambda.function_name
55+ }
56+ }
57+ }
58+ }
59+
60+ resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_medium" {
61+ alarm_name = " search_patient_error_count_medium"
62+ alarm_description = " Triggers when search patient lambda error count is between 4 and 6 within 2mins"
63+ comparison_operator = " GreaterThanThreshold"
64+ threshold = 0
65+ evaluation_periods = 1
66+ alarm_actions = [module . search_patient_alarm_topic . arn ]
67+ ok_actions = [module . search_patient_alarm_topic . arn ]
68+ tags = {
69+ is_kpi = " true"
70+ alarm_group = module.search- patient- details- lambda.function_name
71+ alarm_metric = " Errors"
72+ severity = " medium"
73+ }
74+ metric_query {
75+ id = " error"
76+ label = " error count for search patient, medium if between 4 and 6"
77+ return_data = true
78+ expression = " IF(m1 >= 4 AND m1 <= 6, 1, 0)"
79+ }
80+
81+ metric_query {
82+ id = " m1"
83+
84+ metric {
85+ metric_name = " Errors"
86+ namespace = " AWS/Lambda"
87+ period = 120
88+ stat = " Sum"
89+ dimensions = {
90+ FunctionName = module.search- patient- details- lambda.function_name
91+ }
92+ }
93+ }
94+ }
95+
96+ resource "aws_cloudwatch_metric_alarm" "search_patient_error_count_high" {
97+ alarm_name = " search_patient_error_count_high"
98+ alarm_description = " Triggers when search patient lambda error count is 7 or above"
99+ comparison_operator = " GreaterThanThreshold"
100+ threshold = 0
101+ evaluation_periods = 1
102+ alarm_actions = [module . search_patient_alarm_topic . arn ]
103+ ok_actions = [module . search_patient_alarm_topic . arn ]
104+ tags = {
105+ is_kpi = " true"
106+ alarm_group = module.search- patient- details- lambda.function_name
107+ alarm_metric = " Errors"
108+ severity = " high"
109+ }
110+ metric_query {
111+ id = " error"
112+ label = " error count for search patient, high if 7 or above"
113+ return_data = true
114+ expression = " IF(m1 >= 7, 1, 0)"
115+ }
116+
117+ metric_query {
118+ id = " m1"
119+
120+ metric {
121+ metric_name = " Errors"
122+ namespace = " AWS/Lambda"
123+ period = 120
124+ stat = " Sum"
125+ dimensions = {
126+ FunctionName = module.search- patient- details- lambda.function_name
127+ }
128+ }
129+ }
130+ }
131+
132132module "search_patient_alarm_topic" {
133133 source = " ./modules/sns"
134134 sns_encryption_key_id = module. sns_encryption_key . id
@@ -160,19 +160,18 @@ module "search_patient_alarm_topic" {
160160}
161161
162162
163- # resource "aws_sns_topic_subscription" "im_alerting_search_patient" {
164- # endpoint = module.im-alerting-lambda.lambda_arn
165- # protocol = "lambda"
166- # topic_arn = module.search_patient_alarm_topic.arn
167- # }
168- #
169- # resource "aws_lambda_permission" "im_alerting_invoke_with_search_patient_sns" {
170- # statement_id = "AllowExecutionFromSeachPatientAlarmSNS"
171- # action = "lambda:InvokeFunction"
172- # function_name = module.im-alerting-lambda.lambda_arn
173- # principal = "sns.amazonaws.com"
174- # source_arn = module.search_patient_alarm_topic.arn
175- # }
163+ resource "aws_sns_topic_subscription" "im_alerting_search_patient" {
164+ endpoint = module. im-alerting-lambda . lambda_arn
165+ protocol = " lambda"
166+ topic_arn = module. search_patient_alarm_topic . arn
167+ }
168+ resource "aws_lambda_permission" "im_alerting_invoke_with_search_patient_sns" {
169+ statement_id = " AllowExecutionFromSeachPatientAlarmSNS"
170+ action = " lambda:InvokeFunction"
171+ function_name = module. im-alerting-lambda . lambda_arn
172+ principal = " sns.amazonaws.com"
173+ source_arn = module. search_patient_alarm_topic . arn
174+ }
176175
177176module "search-patient-details-lambda" {
178177 source = " ./modules/lambda"
0 commit comments