-
Notifications
You must be signed in to change notification settings - Fork 2
/
tf-alarms.tf
58 lines (54 loc) · 3.15 KB
/
tf-alarms.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
locals {
alarms = {
retention-errors = {
description = "Errors occurred invoking the ${aws_lambda_function.log_retention.function_name} function! Log groups are not getting default retention.",
comparison_operator = "GreaterThanThreshold"
threshold = aws_lambda_function_event_invoke_config.log_retention.maximum_retry_attempts # Set to value of max retry attempts (2) because if all attempts fail we will see `retry attempts + 1 primary attempt` failures (3). Alarm only when all fail.
period = (aws_lambda_function.log_retention.timeout * (aws_lambda_function_event_invoke_config.log_retention.maximum_retry_attempts + 1)) + 60
metric_name = "Errors"
function_name = aws_lambda_function.log_retention.function_name
}
retention-throttles = {
description = "The ${aws_lambda_function.log_retention.function_name} function was throttled! Log groups are not getting default retention.",
comparison_operator = "GreaterThanThreshold"
threshold = 0
period = 300
metric_name = "Throttles"
function_name = aws_lambda_function.log_retention.function_name
}
global-retention-errors = {
description = "Errors occurred invoking the ${aws_lambda_function.global_log_retention.function_name} function! Log groups are not getting default retention.",
comparison_operator = "GreaterThanThreshold"
threshold = aws_lambda_function_event_invoke_config.global_log_retention.maximum_retry_attempts # Set to value of max retry attempts (2) because if all attempts fail we will see `retry attempts + 1 primary attempt` failures (3). Alarm only when all fail.
period = (aws_lambda_function.global_log_retention.timeout * (aws_lambda_function_event_invoke_config.global_log_retention.maximum_retry_attempts + 1)) + 60
metric_name = "Errors"
function_name = aws_lambda_function.global_log_retention.function_name
}
global-retention-throttles = {
description = "The ${aws_lambda_function.global_log_retention.function_name} function was throttled! Log groups are not getting default retention.",
comparison_operator = "GreaterThanThreshold"
threshold = 0
period = 300
metric_name = "Throttles"
function_name = aws_lambda_function.global_log_retention.function_name
}
}
}
resource "aws_cloudwatch_metric_alarm" "alarm" {
for_each = local.enable_alarms ? local.alarms : {}
alarm_name = "${var.name}-${each.key}"
alarm_description = each.value.description
comparison_operator = each.value.comparison_operator
threshold = each.value.threshold
evaluation_periods = 1
metric_name = each.value.metric_name
namespace = "AWS/Lambda"
period = each.value.period
statistic = "Sum"
actions_enabled = true
alarm_actions = [local.sns_topic_arn]
ok_actions = []
insufficient_data_actions = []
dimensions = { FunctionName = each.value.function_name }
tags = var.tags
}