-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda.tf
58 lines (48 loc) · 1.34 KB
/
lambda.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
resource "aws_iam_role" "iam_for_lambda" {
name = "role-${var.function_name}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "basic" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
role = aws_iam_role.iam_for_lambda.name
}
resource "aws_lambda_function" "main" {
filename = "${path.module}/lambda_package.zip"
function_name = var.function_name
role = aws_iam_role.iam_for_lambda.arn
handler = "lambda_function.lambda_handler"
layers = [aws_lambda_layer_version.lambda_layer.arn]
runtime = "python3.9"
environment {
variables = {
TOKEN = var.token
URL_DISC = var.url
}
}
}
resource "aws_lambda_layer_version" "lambda_layer" {
filename = "${path.module}/layer.zip"
layer_name = "layer-requests"
compatible_runtimes = ["python3.9"]
}
resource "aws_lambda_permission" "with_sns" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.main.function_name
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.topic.arn
}