|
| 1 | +provider "aws" { |
| 2 | +} |
| 3 | + |
| 4 | +resource "aws_cloudwatch_metric_alarm" "app_dlq_messages_alarm" { |
| 5 | + alarm_name = "${var.resource_prefix}-sqs-dlq-present" |
| 6 | + alarm_description = "Items are present in the application DLQ, meaning some messages failed to process." |
| 7 | + namespace = "AWS/SQS" |
| 8 | + metric_name = "ApproximateNumberOfMessagesVisible" |
| 9 | + statistic = "Maximum" |
| 10 | + period = 60 |
| 11 | + evaluation_periods = 1 |
| 12 | + comparison_operator = "GreaterThanThreshold" |
| 13 | + threshold = 0 |
| 14 | + dimensions = [ |
| 15 | + { |
| 16 | + Name = "QueueName" |
| 17 | + Value = "${var.resource_prefix}-sqs-dlq" |
| 18 | + } |
| 19 | + ] |
| 20 | + alarm_actions = [ |
| 21 | + var.priority_sns_arn |
| 22 | + ] |
| 23 | +} |
| 24 | + |
| 25 | +resource "aws_cloudwatch_metric_alarm" "app_latency_alarm" { |
| 26 | + alarm_name = "${var.resource_prefix}-latency-high" |
| 27 | + alarm_description = "Trailing Mean - 95% API gateway latency is > 1.25s for 2 times in 4 minutes." |
| 28 | + namespace = "AWS/Lambda" |
| 29 | + metric_name = "UrlRequestLatency" |
| 30 | + extended_statistic = "tm95" |
| 31 | + period = "120" |
| 32 | + evaluation_periods = "2" |
| 33 | + comparison_operator = "GreaterThanThreshold" |
| 34 | + threshold = "1250" |
| 35 | + alarm_actions = [ |
| 36 | + var.standard_sns_arn |
| 37 | + ] |
| 38 | + dimensions = [ |
| 39 | + { |
| 40 | + Name = "FunctionName" |
| 41 | + Value = "${var.resource_prefix}-lambda" |
| 42 | + } |
| 43 | + ] |
| 44 | +} |
| 45 | + |
| 46 | +resource "aws_cloudwatch_metric_alarm" "app_no_requests_alarm" { |
| 47 | + alarm_name = "${var.resource_prefix}-no-requests" |
| 48 | + alarm_description = "No requests have been received in the past 5 minutes." |
| 49 | + namespace = "AWS/Lambda" |
| 50 | + metric_name = "UrlRequestCount" |
| 51 | + statistic = "Sum" |
| 52 | + period = "300" |
| 53 | + evaluation_periods = "1" |
| 54 | + comparison_operator = "LessThanThreshold" |
| 55 | + threshold = "1" |
| 56 | + alarm_actions = [ |
| 57 | + var.priority_sns_arn |
| 58 | + ] |
| 59 | + dimensions = [ |
| 60 | + { |
| 61 | + Name = "FunctionName" |
| 62 | + Value = "${var.resource_prefix}-lambda" |
| 63 | + } |
| 64 | + ] |
| 65 | +} |
| 66 | + |
| 67 | +resource "aws_cloudwatch_metric_alarm" "app_invocation_error_alarm" { |
| 68 | + alarm_name = "${var.resource_prefix}-error-invocation" |
| 69 | + alarm_description = "Lambda threw an error, meaning the init of the application itself has encountered an error" |
| 70 | + namespace = "AWS/Lambda" |
| 71 | + metric_name = "Errors" |
| 72 | + statistic = "Sum" |
| 73 | + period = "300" |
| 74 | + evaluation_periods = "1" |
| 75 | + comparison_operator = "GreaterThanThreshold" |
| 76 | + threshold = "1" |
| 77 | + alarm_actions = [ |
| 78 | + var.priority_sns_arn |
| 79 | + ] |
| 80 | + dimensions = [ |
| 81 | + { |
| 82 | + Name = "FunctionName" |
| 83 | + Value = "${var.resource_prefix}-lambda" |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
| 87 | + |
| 88 | +resource "aws_cloudwatch_metric_alarm" "app5xx_error_alarm" { |
| 89 | + alarm_name = "${var.resource_prefix}-cloudfront-5xx-error" |
| 90 | + alarm_description = "Main application responses are more than 1% 5xx errors (from Cloudfront)" |
| 91 | + namespace = "AWS/CloudFront" |
| 92 | + metric_name = "5xxErrorRate" |
| 93 | + statistic = "Average" |
| 94 | + period = "300" |
| 95 | + evaluation_periods = "1" |
| 96 | + comparison_operator = "GreaterThanThreshold" |
| 97 | + threshold = "1" |
| 98 | + alarm_actions = [ |
| 99 | + var.priority_sns_arn |
| 100 | + ] |
| 101 | + dimensions = [ |
| 102 | + { |
| 103 | + Name = "DistributionId" |
| 104 | + Value = var.main_cloudfront_distribution_id |
| 105 | + } |
| 106 | + ] |
| 107 | +} |
0 commit comments