forked from builtinnya/aws-sns-slack-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
75 lines (61 loc) · 1.54 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#####
# Providers
#
provider "aws" {
version = "~> 2.33.0"
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
#####
# Modules
#
module "sns_to_slack" {
source = "../../module-v0.12"
slack_webhook_url = var.slack_webhook_url
slack_channel_map = var.slack_channel_map
}
#####
# CloudWatch Alarms
#
resource "aws_cloudwatch_metric_alarm" "lambda_duration" {
alarm_name = "lambda-duration"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "Duration"
namespace = "AWS/Lambda"
period = "120"
statistic = "Average"
threshold = "500"
alarm_description = "This metric monitors AWS Lambda duration"
insufficient_data_actions = [
aws_sns_topic.test_alarms.arn,
]
alarm_actions = [
aws_sns_topic.test_alarms.arn,
]
ok_actions = [
aws_sns_topic.test_alarms.arn,
]
}
#####
# SNS Topics
#
resource "aws_sns_topic" "test_alarms" {
name = "test-alarms"
}
#####
# SNS Subscriptions
#
resource "aws_lambda_permission" "allow_lambda_sns_to_slack" {
statement_id = "AllowSNSToSlackExecutionFromSNS"
action = "lambda:invokeFunction"
function_name = module.sns_to_slack.lambda_function_arn
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.test_alarms.arn
}
resource "aws_sns_topic_subscription" "lambda_sns_to_slack" {
topic_arn = aws_sns_topic.test_alarms.arn
protocol = "lambda"
endpoint = module.sns_to_slack.lambda_function_arn
}