-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
68 lines (55 loc) · 1.43 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
#####
# Providers
#
provider "aws" {
region = "${var.region}"
}
#####
# Modules
#
module "sns_to_webex_teams" {
source = "../.."
webex_teams_channel_map = "${var.webex_teams_channel_map}"
webex_teams_bearer_token = "${var.webex_teams_bearer_token}"
}
#####
# CloudWatch Alarms
#
resource "aws_cloudwatch_metric_alarm" "lambda_duration" {
alarm_name = "lambda-duration"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "Duration"
namespace = "AWS/Lambda"
period = "300"
extended_statistic = "p95"
threshold = "5000"
alarm_description = "This metric monitors AWS Lambda duration"
alarm_actions = [
"${aws_sns_topic.production_notices.arn}"
]
ok_actions = [
"${aws_sns_topic.production_notices.arn}"
]
}
#####
# SNS Topics
#
resource "aws_sns_topic" "production_notices" {
name = "production-notices"
}
#####
# SNS Subscriptions
#
resource "aws_lambda_permission" "allow_lambda_sns_to_webex_teams" {
statement_id = "AllowSNSToWebexTeamsExecutionFromSNS"
action = "lambda:invokeFunction"
function_name = "${module.sns_to_webex_teams.lambda_function_arn}"
principal = "sns.amazonaws.com"
source_arn = "${aws_sns_topic.production_notices.arn}"
}
resource "aws_sns_topic_subscription" "lambda_sns_to_webex_teams" {
topic_arn = "${aws_sns_topic.production_notices.arn}"
protocol = "lambda"
endpoint = "${module.sns_to_webex_teams.lambda_function_arn}"
}