-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.tf
70 lines (65 loc) · 1.78 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
59
60
61
62
63
64
65
66
67
68
69
70
# provider aws
provider "aws" {
region = "us-west-2"
}
# resource iam role with policy to invoke lambda
# form many methods, use the same role
resource "aws_iam_role" "role" {
name = var.ROLE_NAME
// assume role policy lambda
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
}
// policy to logs
resource "aws_iam_role_policy" "logs" {
name = "logs"
role = aws_iam_role.role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
Effect = "Allow"
Resource = "arn:aws:logs:*:*:*"
},
]
})
}
# deploye lambda function
resource "aws_lambda_function" "lambda_function" {
function_name = var.LAMBDA_FUNCTION_NAME
handler = var.HANDLER
filename = data.archive_file.lambda_zip.output_path
role = aws_iam_role.role.arn
runtime = "go1.x"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
depends_on = [data.archive_file.lambda_zip]
timeouts {
create = "1m"
}
}
// data "aws_caller_identity" "current" {}
// lambda permisson
// resource "aws_lambda_permission" "apigw_lambda" {
// count = var.API_ID != "" ? 1 : 0
//
// statement_id = "AllowExecutionFromAPIGateway"
// action = "lambda:InvokeFunction"
// function_name = aws_lambda_function.lambda_function.function_name
// principal = "apigateway.amazonaws.com"
// source_arn = "arn:aws:execute-api:us-west-2:${data.aws_caller_identity.current.account_id}:${var.API_ID}/*/*/*"
// }