Skip to content

Commit 9cd3c8d

Browse files
committed
set up metric filter pattern and fix tf apply
1 parent 30709fd commit 9cd3c8d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

infrastructure/instance/endpoints.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module "get_status" {
1515
function_name = "get_status"
1616
image_uri = module.docker_image.image_uri
1717
policy_json = data.aws_iam_policy_document.logs_policy_document.json
18+
aws_sns_topic = data.aws_sns_topic.fhir_api_errors.arn
1819
}
1920

2021
locals {

infrastructure/instance/modules/lambda/lambda.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ resource "aws_cloudwatch_log_metric_filter" "fhir_api_error_logs" {
5555
count = var.error_alarm_notifications_enabled ? 1 : 0
5656

5757
name = "${local.short_prefix}_${var.function_name}-ErrorLogsFilter"
58-
pattern = "%\\[ERROR\\]%"
59-
log_group_name = aws_cloudwatch_log_group.api_access_log.name
58+
pattern = "{ $.operation_outcome.status = \"500\" || $.operation_outcome.status = \"403\" }"
59+
log_group_name = module.lambda_function_container_image.lambda_cloudwatch_log_group_name
6060

6161
metric_transformation {
6262
name = "${local.short_prefix}_${var.function_name}-ApiErrorLogs"
@@ -77,6 +77,6 @@ resource "aws_cloudwatch_metric_alarm" "fhir_api_error_alarm" {
7777
statistic = "Sum"
7878
threshold = 1
7979
alarm_description = "This sets off an alarm for any error logs found in fhir api Lambda function"
80-
alarm_actions = [data.aws_sns_topic.fhir_api_errors.arn]
80+
alarm_actions = var.aws_sns_topic != null ? [var.aws_sns_topic] : []
8181
treat_missing_data = "notBreaching"
8282
}

infrastructure/instance/modules/lambda/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ variable "function_name" {
1010
type = string
1111
}
1212

13+
variable "aws_sns_topic" {
14+
description = "SNS topic ARN for CloudWatch alarm notifications"
15+
type = string
16+
default = null
17+
}
18+
variable "error_alarm_notifications_enabled" {
19+
description = "useful switching error alerting between environment"
20+
type = string
21+
}
22+
1323
variable "image_uri" {
1424
type = string
1525
}

0 commit comments

Comments
 (0)