-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVC-DAL.tf
62 lines (56 loc) · 2.22 KB
/
VC-DAL.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
locals {
VC-DAL_srcdir_path = "./VC-DAL"
VC-DAL_output_path = "./VC-DAL/VC-DAL.zip"
VC-DAL-layer_output_path = "./VC-DAL/VC-DAL-layer.zip"
}
resource "aws_lambda_permission" "invoke-VC-DAL" {
statement_id = "AllowExecFromScraperAPI"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.VC-DAL.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.VCAPI.execution_arn}/*"
}
data "archive_file" "VC-DALArchive" {
type = "zip"
output_file_mode = "0666"
source_dir = local.VC-DAL_srcdir_path
output_path = local.VC-DAL_output_path
excludes = ["VC-DAL.zip", "node_modules", "VC-DAL-layer.zip", "nodejs", "prepare-layer.bat"]
}
resource "aws_lambda_function" "VC-DAL" {
depends_on = [
data.archive_file.VC-DALArchive
]
function_name = "VC-DAL"
role = aws_iam_role.lambda-role.arn
filename = "VC-DAL/VC-DAL.zip"
handler = "VC-DAL.VCDAL"
runtime = "nodejs16.x"
memory_size = 1024
timeout = 15
source_code_hash = data.archive_file.VC-DALArchive.output_base64sha256
layers = [aws_lambda_layer_version.VC-DAL-node-modules.id, aws_lambda_layer_version.VC-layer.id]
environment {
variables = {
VC_MONGO_URI = local.VC_MONGO_URI
}
}
}
data "archive_file" "VC-DAL-layer-archive" {
type = "zip"
output_file_mode = "0666"
source_dir = local.VC-DAL_srcdir_path
output_path = local.VC-DAL-layer_output_path
excludes = ["VC-DAL.zip", "package.json", "package-lock.json", "VC-DAL.mjs", "VC-DAL.js", "outputs.json", "VC-DAL-layer.zip", "node_modules", "prepare-layer.bat"]
}
resource "aws_lambda_layer_version" "VC-DAL-node-modules" {
depends_on = [
data.archive_file.VC-DAL-layer-archive
]
description = "layer for VC-DAL/node_modules which includes: node-fetch and mongoDB"
layer_name = "VC-DAL-node-modules"
filename = data.archive_file.VC-DAL-layer-archive.output_path
compatible_runtimes = ["nodejs16.x"]
compatible_architectures = ["x86_64"]
source_code_hash = data.archive_file.VC-DAL-layer-archive.output_base64sha256
}