-
Notifications
You must be signed in to change notification settings - Fork 34
/
lambda.tf
79 lines (67 loc) · 2.15 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
71
72
73
74
75
76
77
78
79
resource "random_string" "name" {
length = 4
special = false
upper = false
}
data "archive_file" "dir_hash_zip" {
type = "zip"
source_dir = "${var.source_code_path}/"
output_path = "${path.module}/dir_hash_zip"
}
resource "null_resource" "install_python_dependencies" {
triggers = {
requirements = "${sha1(file("${var.source_code_path}/requirements.txt"))}"
dir_hash = "${data.archive_file.dir_hash_zip.output_base64sha256}"
}
provisioner "local-exec" {
command = "bash ${path.module}/scripts/py_pkg.sh"
environment = {
source_code_path = var.source_code_path
path_cwd = path.cwd
path_module = path.module
runtime = var.runtime
function_name = var.function_name
random_string = random_string.name.result
}
}
}
data "archive_file" "lambda_zip" {
depends_on = [null_resource.install_python_dependencies]
type = "zip"
source_dir = "${path.cwd}/lambda_pkg_${random_string.name.result}/"
output_path = var.output_path
}
# have to defined a lambda with and without dead_letter_config. _sigh_
resource "aws_lambda_function" "lambda" {
count = var.dlc_target_arn != null ? 1 : 0
filename = var.output_path
description = var.description
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
role = var.role_arn
function_name = var.function_name
handler = var.handler_name
runtime = var.runtime
timeout = var.timeout
memory_size = var.memory_size
environment {
variables = var.environment
}
dead_letter_config {
target_arn = var.dlc_target_arn
}
}
resource "aws_lambda_function" "lambda_nodlc" {
count = var.dlc_target_arn == null ? 1 : 0
filename = var.output_path
description = var.description
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
role = var.role_arn
function_name = var.function_name
handler = var.handler_name
runtime = var.runtime
timeout = var.timeout
memory_size = var.memory_size
environment {
variables = var.environment
}
}