-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.tf
More file actions
71 lines (58 loc) · 1.85 KB
/
lambda.tf
File metadata and controls
71 lines (58 loc) · 1.85 KB
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
data "aws_iam_role" "lambda_exec_role" {
name = "tc-infra-id-lambda-exec-role"
}
data "aws_dynamodb_table" "identification_table" {
name = "tc-identification-table"
}
resource "aws_iam_role_policy" "lambda_dynamodb_policy" {
role = data.aws_iam_role.lambda_exec_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:GetItem"
]
Resource = [
data.aws_dynamodb_table.identification_table.arn,
"${data.aws_dynamodb_table.identification_table.arn}/index/*"
]
}]
})
}
resource "aws_iam_role_policy_attachment" "lambda_logs" {
role = data.aws_iam_role.lambda_exec_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
data "aws_security_group" "id_lambda" {
name = "tc-id-lambda-sg"
vpc_id = data.aws_vpc.tc_lambda_vpc.id
}
resource "aws_lambda_function" "id_lambda" {
function_name = "lambda-identification-client"
role = data.aws_iam_role.lambda_exec_role.arn
handler = "tech.buildrun.lambda.HandlerClient::handleRequest"
runtime = "java17"
timeout = 30
filename = var.lambda_jar_path
source_code_hash = filebase64sha256(var.lambda_jar_path)
environment {
variables = {
TABLE_NAME = "tc-identification-table"
}
}
vpc_config {
subnet_ids = data.aws_subnets.tc_lambda_subnets.ids
security_group_ids = [data.aws_security_group.id_lambda.id]
}
tags = var.tags
}
resource "aws_lambda_permission" "apigw_invoke_lambda" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.id_lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${data.aws_apigatewayv2_api.tc_api.execution_arn}/*/*"
}