-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaling_agent.tf
More file actions
49 lines (40 loc) · 1.48 KB
/
Copy pathscaling_agent.tf
File metadata and controls
49 lines (40 loc) · 1.48 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
resource "aws_cloudwatch_log_group" "scaling_agent" {
name = "/aws/lambda/${var.project_name}-scaling-agent"
retention_in_days = 14
}
# The policy layer. Runs on a schedule: reads the scheduler's desired-vs-current
# worker count and asynchronously invokes N worker Lambdas to close the gap.
# Scale-down is implicit — workers self-retire at their lifetime, so the agent
# never has to kill anything (mirrors the Fused rt_scaling design).
resource "aws_lambda_function" "scaling_agent" {
function_name = "${var.project_name}-scaling-agent"
role = aws_iam_role.scaling_agent.arn
package_type = "Image"
image_uri = "${aws_ecr_repository.scaling_agent.repository_url}:${var.worker_image_tag}"
memory_size = 256
timeout = 60
vpc_config {
subnet_ids = module.vpc.private_subnets
security_group_ids = [aws_security_group.worker.id]
}
environment {
variables = {
SCHEDULER_DASHBOARD = local.scheduler_dashboard
WORKER_FUNCTION_ARN = aws_lambda_function.worker.arn
MAX_WORKERS = tostring(var.max_workers)
}
}
depends_on = [aws_cloudwatch_log_group.scaling_agent]
}
resource "aws_scheduler_schedule" "scaling_agent" {
name = "${var.project_name}-scaling-agent"
group_name = "default"
flexible_time_window {
mode = "OFF"
}
schedule_expression = var.scaling_interval
target {
arn = aws_lambda_function.scaling_agent.arn
role_arn = aws_iam_role.scheduler_invoke.arn
}
}