Skip to content

Commit 38ebd5d

Browse files
committed
Attempt Cloudwatch alarm setup
1 parent 3b19550 commit 38ebd5d

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_sns_topic" "batch_processor_errors" {
2+
name = "${local.short_prefix}-batch-processor-errors"
3+
}
4+
5+
resource "aws_sns_topic_policy" "batch_processor_errors_topic_policy" {
6+
arn = aws_sns_topic.batch_processor_errors.arn
7+
policy = jsonencode({
8+
Version = "2012-10-17",
9+
Statement = [
10+
{
11+
Sid = "AllowCloudWatchToPublish",
12+
Effect = "Allow",
13+
Principal = {
14+
Service = "cloudwatch.amazonaws.com"
15+
},
16+
Action = "SNS:Publish",
17+
Resource = aws_sns_topic.batch_processor_errors.arn
18+
}
19+
]
20+
})
21+
}
22+
23+
resource "aws_sns_topic_subscription" "batch_processor_errors_email_target" {
24+
topic_arn = aws_sns_topic.batch_processor_errors.arn
25+
protocol = "email"
26+
endpoint = var.batch_processor_errors_target_email
27+
}

terraform/file_name_processor.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,29 @@ resource "aws_cloudwatch_log_group" "file_name_processor_log_group" {
318318
name = "/aws/lambda/${local.short_prefix}-filenameproc_lambda"
319319
retention_in_days = 30
320320
}
321+
322+
resource "aws_cloudwatch_log_metric_filter" "file_name_processor_error_logs" {
323+
name = "${local.short_prefix}-FilenameProcessorErrorLogsFilter"
324+
pattern = "%\\[ERROR\\]|\\[CRITICAL\\]%"
325+
log_group_name = aws_cloudwatch_log_group.file_name_processor_log_group.name
326+
327+
metric_transformation {
328+
name = "${local.short_prefix}-FilenameProcessorErrorLogs"
329+
namespace = "${local.short_prefix}-FilenameProcessorLambda"
330+
value = "1"
331+
}
332+
}
333+
334+
resource "aws_cloudwatch_metric_alarm" "file_name_processor_error_alarm" {
335+
alarm_name = "${local.short_prefix}-file-name-processor-lambda-error"
336+
comparison_operator = "GreaterThanOrEqualToThreshold"
337+
evaluation_periods = 1
338+
metric_name = "${local.short_prefix}-FilenameProcessorErrorLogs"
339+
namespace = "${local.short_prefix}-FilenameProcessorLambda"
340+
period = 60
341+
statistic = "Count"
342+
threshold = 1
343+
alarm_description = "This sets off an alarm for any error logs found in the file name processor Lambda function"
344+
alarm_actions = [aws_sns_topic.batch_processor_errors.arn]
345+
treat_missing_data = "notBreaching"
346+
}

terraform/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ variable "sub_environment" {
77
variable "immunisation_account_id" {}
88
variable "dspp_core_account_id" {}
99

10+
# TODO - change this. Get a shared mailbox/switch to Lambda -> Slack integration
11+
# Also should have different config for Prod vs PTL
12+
variable "batch_processor_errors_target_email" {
13+
default = "[email protected]"
14+
description = "The target email address for the Batch Processor Errors SNS topic"
15+
type = string
16+
}
17+
1018
variable "create_mesh_processor" {
1119
default = false
1220
}

0 commit comments

Comments
 (0)