-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdas.tf
More file actions
185 lines (162 loc) · 5.85 KB
/
lambdas.tf
File metadata and controls
185 lines (162 loc) · 5.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
###################
# Lambda Functions
###################
# Data source for Lambda function code
data "archive_file" "lambda_zip" {
type = "zip"
source_dir = "${path.module}/src"
output_path = "${path.module}/.terraform/lambda.zip"
excludes = ["**/*.md", "**/.DS_Store"]
}
# Webhook Lambda
resource "aws_lambda_function" "webhook" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-webhook"
role = aws_iam_role.lambda_execution.arn
handler = "webhook/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 30
memory_size = 512
environment {
variables = merge(
local.common_lambda_environment,
{
STATE_MACHINE_ARN = aws_sfn_state_machine.video_generation.arn
ALLOWED_USERS = jsonencode(var.allowed_telegram_users)
}
)
}
}
# Transcribe Lambda
resource "aws_lambda_function" "transcribe" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-transcribe"
role = aws_iam_role.lambda_execution.arn
handler = "transcribe/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 180
memory_size = 512
environment {
variables = local.common_lambda_environment
}
}
# Scripter Lambda
resource "aws_lambda_function" "script_generator" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-scripter"
role = aws_iam_role.lambda_execution.arn
handler = "scripter/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 60
memory_size = 512
environment {
variables = local.common_lambda_environment
}
}
# Video Animator Lambda
resource "aws_lambda_function" "video_generator" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-video-animator"
role = aws_iam_role.lambda_execution.arn
handler = "video-animator/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 600 # 10 minutes for video generation
memory_size = 1024
environment {
variables = local.common_lambda_environment
}
}
# Send Video Lambda
resource "aws_lambda_function" "send_video" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-send-video"
role = aws_iam_role.lambda_execution.arn
handler = "send-video/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 120
memory_size = 1024
environment {
variables = local.common_lambda_environment
}
}
# Send Script Lambda
resource "aws_lambda_function" "send_script" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-send-script"
role = aws_iam_role.lambda_execution.arn
handler = "send-script/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 30
memory_size = 512
environment {
variables = local.common_lambda_environment
}
}
# kie.ai Callback Lambda
resource "aws_lambda_function" "kie_callback" {
filename = data.archive_file.lambda_zip.output_path
function_name = "${local.name_prefix}-kie-callback"
role = aws_iam_role.lambda_execution.arn
handler = "kie-callback/index.handler"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = var.lambda_runtime
timeout = 120
memory_size = 1024
environment {
variables = local.common_lambda_environment
}
}
###################
# API Gateway for Webhook
###################
resource "aws_apigatewayv2_api" "webhook" {
name = "${local.name_prefix}-webhook"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_stage" "webhook" {
api_id = aws_apigatewayv2_api.webhook.id
name = "$default"
auto_deploy = true
}
resource "aws_apigatewayv2_integration" "webhook" {
api_id = aws_apigatewayv2_api.webhook.id
integration_type = "AWS_PROXY"
integration_uri = aws_lambda_function.webhook.invoke_arn
integration_method = "POST"
}
resource "aws_apigatewayv2_route" "webhook" {
api_id = aws_apigatewayv2_api.webhook.id
route_key = "POST /webhook"
target = "integrations/${aws_apigatewayv2_integration.webhook.id}"
}
resource "aws_apigatewayv2_integration" "kie_callback" {
api_id = aws_apigatewayv2_api.webhook.id
integration_type = "AWS_PROXY"
integration_uri = aws_lambda_function.kie_callback.invoke_arn
integration_method = "POST"
}
resource "aws_apigatewayv2_route" "kie_callback" {
api_id = aws_apigatewayv2_api.webhook.id
route_key = "POST /kie-callback"
target = "integrations/${aws_apigatewayv2_integration.kie_callback.id}"
}
resource "aws_lambda_permission" "webhook_api_gateway" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.webhook.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.webhook.execution_arn}/*/*"
}
resource "aws_lambda_permission" "kie_callback_api_gateway" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.kie_callback.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.webhook.execution_arn}/*/*"
}