forked from kj4c/Alphas_Propex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_variables.py
More file actions
63 lines (52 loc) · 2.02 KB
/
update_variables.py
File metadata and controls
63 lines (52 loc) · 2.02 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
import os
backend_dir = "backend"
variables_file = "variables.tf"
lambda_functions = {}
for function in os.listdir(backend_dir):
function_path = os.path.join(backend_dir, function)
handler_file = os.path.join(function_path, "handler.py")
method_file = os.path.join(function_path, "method.txt")
if os.path.isdir(function_path) and os.path.exists(handler_file):
#Read HTTP method from method.txt (default to GET if missing)
method = "POST"
if os.path.exists(method_file):
with open(method_file, "r") as mf:
content = mf.read().strip().upper()
if content in ["GET", "POST", "PUT", "DELETE"]:
method = content
else:
print(f"⚠️ Invalid or empty method in {method_file}, defaulting to POST")
lambda_functions[function] = {
"handler": "handler.lambda_handler",
"runtime": "python3.9",
"method": method
}
# Generate updated variables.tf content
variables_tf_content = """# AWS Region
variable "aws_region" {
description = "The AWS region to deploy resources in"
default = "us-east-1"
}
variable "lambda_bucket_name" {
description = "The name of the existing S3 bucket where Lambda ZIPs will be stored"
default = "alphas-lambda-bucket"
}
variable "lambda_functions" {
description = "Map of Lambda function configurations"
type = map(object({
handler = string
runtime = string
method = string
}))
# Auto-detected functions from backend/
default = {
"""
for func_name, config in lambda_functions.items():
if (func_name == "price_prediction"):
continue
variables_tf_content += f' "{func_name}" = {{ handler = "{config["handler"]}", runtime = "{config["runtime"]}", method = "{config["method"]}" }}\n'
variables_tf_content += " }\n}"
# Write updated variables.tf
with open(variables_file, "w") as f:
f.write(variables_tf_content)
print("✅ Updated variables.tf with detected Lambda functions and methods.")