-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.tf
77 lines (68 loc) · 2.3 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
data "archive_file" "scale_up" {
type = "zip"
source_dir = "${path.root}/lambda/scale-up/"
output_path = "${path.root}/assets/scale-up/lambda.zip"
}
resource "aws_lambda_function" "scale_up_lambda" {
function_name = "scale-up"
role = var.lambda_role
handler = "index.handler"
runtime = "nodejs18.x"
filename = data.archive_file.scale_up.output_path
timeout = 900
source_code_hash = data.archive_file.scale_up.output_base64sha256
environment {
variables = {
BIG_AUTO_SCALING_NAME : aws_autoscaling_group.tidybase_large_asg.name
TINY_AUTO_SCALING_NAME : aws_autoscaling_group.tidybase_small_asg.name
TARGET_GROUP_ARN : aws_lb_target_group.tidybase_target_group.arn
}
}
}
resource "aws_lambda_function_url" "scale_up_lambda" {
function_name = aws_lambda_function.scale_up_lambda.function_name
authorization_type = "NONE"
cors {
allow_origins = ["*"]
allow_headers = ["*"]
allow_methods = ["*"]
expose_headers = ["*"]
}
}
output "lambda_scale_up_function_url" {
value = aws_lambda_function_url.scale_up_lambda.function_url
}
data "archive_file" "scale_down" {
type = "zip"
source_dir = "${path.root}/lambda/scale-down/"
output_path = "${path.root}/assets/scale-down/lambda.zip"
}
resource "aws_lambda_function" "scale_down_lambda" {
function_name = "scale-down"
role = var.lambda_role
handler = "index.handler"
runtime = "nodejs18.x"
filename = data.archive_file.scale_down.output_path
timeout = 900
source_code_hash = data.archive_file.scale_down.output_base64sha256
environment {
variables = {
BIG_AUTO_SCALING_NAME : aws_autoscaling_group.tidybase_large_asg.name
TINY_AUTO_SCALING_NAME : aws_autoscaling_group.tidybase_small_asg.name
TARGET_GROUP_ARN : aws_lb_target_group.tidybase_target_group.arn
}
}
}
resource "aws_lambda_function_url" "scale_down_lambda" {
function_name = aws_lambda_function.scale_down_lambda.function_name
authorization_type = "NONE"
cors {
allow_origins = ["*"]
allow_headers = ["*"]
allow_methods = ["*"]
expose_headers = ["*"]
}
}
output "lambda_scale_down_function_url" {
value = aws_lambda_function_url.scale_down_lambda.function_url
}