Skip to content

Commit ddb66c2

Browse files
authored
Replace hardcoded memory_limit values on API and AI Proxy lambdas (#224)
New variables default to the prior hardcoded values. This is needed for BYOC deployments that do not have the Lambda max memory limit (10GB)
1 parent 0fc8937 commit ddb66c2

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ module "services" {
186186
primary_org_name = var.primary_org_name
187187
api_handler_provisioned_concurrency = var.api_handler_provisioned_concurrency
188188
api_handler_reserved_concurrent_executions = var.api_handler_reserved_concurrent_executions
189+
api_handler_memory_limit = var.api_handler_memory_limit
189190
ai_proxy_reserved_concurrent_executions = var.ai_proxy_reserved_concurrent_executions
191+
ai_proxy_memory_limit = var.ai_proxy_memory_limit
190192
whitelisted_origins = var.whitelisted_origins
191193
outbound_rate_limit_window_minutes = var.outbound_rate_limit_window_minutes
192194
outbound_rate_limit_max_requests = var.outbound_rate_limit_max_requests
@@ -382,5 +384,3 @@ module "brainstore" {
382384
cache_file_size_writer = var.brainstore_cache_file_size_writer
383385
locks_s3_path = var.brainstore_locks_s3_path
384386
}
385-
386-

modules/services/lambda-aiproxy.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resource "aws_lambda_function" "ai_proxy" {
1313
handler = local.observability_enabled ? local.nodejs_datadog_handler : local.ai_proxy_original_handler
1414
runtime = "nodejs22.x"
1515
architectures = ["arm64"]
16-
memory_size = 10240 # Max that lambda supports
16+
memory_size = var.ai_proxy_memory_limit
1717
reserved_concurrent_executions = var.ai_proxy_reserved_concurrent_executions
1818
timeout = 900
1919
publish = true

modules/services/lambda-apihandler.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ resource "aws_lambda_function" "api_handler" {
7171
role = var.api_handler_role_arn
7272
handler = local.observability_enabled ? local.nodejs_datadog_handler : local.api_handler_original_handler
7373
runtime = "nodejs22.x"
74-
memory_size = 10240 # Max that lambda supports
74+
memory_size = var.api_handler_memory_limit
7575
reserved_concurrent_executions = var.api_handler_reserved_concurrent_executions
7676
timeout = 600
7777
publish = true

modules/services/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,34 @@ variable "api_handler_reserved_concurrent_executions" {
159159
default = -1 # -1 means no reserved concurrency. Use up to the max concurrency limit in your AWS account.
160160
}
161161

162+
variable "api_handler_memory_limit" {
163+
type = number
164+
description = "The maximum memory in MB for the API Handler."
165+
default = 10240
166+
167+
validation {
168+
condition = var.api_handler_memory_limit > 0 && var.api_handler_memory_limit <= 10240
169+
error_message = "The maximum supported value by AWS Lambda is 10240 MB (10 GB)."
170+
}
171+
}
172+
162173
variable "ai_proxy_reserved_concurrent_executions" {
163174
type = number
164175
description = "The number of concurrent executions to reserve for the AI Proxy. Setting this will prevent the AI Proxy from throttling other lambdas in your account. Note this will take away from your global concurrency limit in your AWS account."
165176
default = -1 # -1 means no reserved concurrency. Use up to the max concurrency limit in your AWS account.
166177
}
167178

179+
variable "ai_proxy_memory_limit" {
180+
type = number
181+
description = "The maximum memory in MB for the AI Proxy."
182+
default = 10240
183+
184+
validation {
185+
condition = var.ai_proxy_memory_limit > 0 && var.ai_proxy_memory_limit <= 10240
186+
error_message = "The maximum supported value by AWS Lambda is 10240 MB (10 GB)."
187+
}
188+
}
189+
168190
variable "run_draft_migrations" {
169191
type = bool
170192
description = "Enable draft migrations for database schema updates"

variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,34 @@ variable "api_handler_reserved_concurrent_executions" {
479479
default = -1 # -1 means no reserved concurrency. Use up to the max concurrency limit in your AWS account.
480480
}
481481

482+
variable "api_handler_memory_limit" {
483+
type = number
484+
description = "The maximum memory in MB for the API Handler."
485+
default = 10240
486+
487+
validation {
488+
condition = var.api_handler_memory_limit > 0 && var.api_handler_memory_limit <= 10240
489+
error_message = "The maximum supported value by AWS Lambda is 10240 MB (10 GB)."
490+
}
491+
}
492+
482493
variable "ai_proxy_reserved_concurrent_executions" {
483494
description = "The number of concurrent executions to reserve for the AI Proxy. Setting this will prevent the AI Proxy from throttling other lambdas in your account. Note this will take away from your global concurrency limit in your AWS account."
484495
type = number
485496
default = -1 # -1 means no reserved concurrency. Use up to the max concurrency limit in your AWS account.
486497
}
487498

499+
variable "ai_proxy_memory_limit" {
500+
type = number
501+
description = "The maximum memory in MB for the AI Proxy."
502+
default = 10240
503+
504+
validation {
505+
condition = var.ai_proxy_memory_limit > 0 && var.ai_proxy_memory_limit <= 10240
506+
error_message = "The maximum supported value by AWS Lambda is 10240 MB (10 GB)."
507+
}
508+
}
509+
488510
variable "disable_billing_telemetry_aggregation" {
489511
description = "Disable billing telemetry aggregation. Do not disable this unless instructed by support."
490512
type = bool

0 commit comments

Comments
 (0)