-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda_slack_func.tf
42 lines (35 loc) · 1.17 KB
/
lambda_slack_func.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
data "archive_file" "lambdazip" {
type = "zip"
output_path = "${path.module}/artifacts/sns_slack.zip"
source_dir = "${path.module}/artifacts/lambda/"
}
module "cw_sns_slack" {
source = "./modules/lambda"
name = "sns-slack"
description = "notify slack channel on sns topic"
artifact_file = "${path.module}/artifacts/sns_slack.zip"
handler = "sns_slack.lambda_handler"
runtime = "python3.8"
memory_size = 128
timeout = 30
environment = {
"SLACK_URL" = var.slack_url
"SLACK_CHANNEL" = var.slack_channel
"SLACK_USER" = var.slack_user
}
tags = local.tags
}
resource "aws_sns_topic_subscription" "slack-endpoint" {
endpoint = module.cw_sns_slack.arn
protocol = "lambda"
endpoint_auto_confirms = true
topic_arn = aws_sns_topic.cw_topic.arn
}
# allow lambda to be executed from SNS topic
resource "aws_lambda_permission" "sns_lambda_slack_invoke" {
statement_id = "sns_slackAllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = module.cw_sns_slack.arn
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.cw_topic.arn
}