Skip to content

Commit

Permalink
Add stage_name variable and aws_api_gateway_method_settings resource
Browse files Browse the repository at this point in the history
  • Loading branch information
FloRul committed Feb 12, 2024
1 parent cb91cb4 commit a06f88d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 74 deletions.
12 changes: 12 additions & 0 deletions lambdas/inference/lambda_integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ module "api_gateway" {
lambda_function_arn = module.lambda_function_container_image.lambda_function_arn
lambda_function_name = var.lambda_function_name
}

resource "aws_api_gateway_method_settings" "this" {
rest_api_id = var.api_gateway_rest_api_id
stage_name = var.stage_name
method_path = "${local.api_gateway_path_part}/${local.api_gateway_http_method}"
settings {
metrics_enabled = true
logging_level = "INFO"
throttling_rate_limit = 50
throttling_burst_limit = 100
}
}
7 changes: 6 additions & 1 deletion lambdas/inference/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ variable "api_gateway_rest_api_id" {
variable "api_gateway_rest_api_root_resource_id" {
type = string
nullable = false
}
}

variable "stage_name" {
type = string
nullable = false
}
22 changes: 8 additions & 14 deletions terraform/api_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,19 @@ resource "aws_api_gateway_usage_plan" "this" {
depends_on = [aws_api_gateway_stage.this]
name = "api_gateway_usage_plan"

throttle_settings {
burst_limit = 100
rate_limit = 50
}

api_stages {
api_id = aws_api_gateway_rest_api.this.id
stage = var.api_gateway_stage_name
throttle {
burst_limit = 50
rate_limit = 10
path = "/inference/GET"
}
}

quota_settings {
limit = 100
offset = 0
period = "DAY"
limit = 1000
offset = 2
period = "WEEK"
}

throttle_settings {
burst_limit = 100
rate_limit = 50
}
}

Expand Down
126 changes: 73 additions & 53 deletions terraform/modules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,104 @@ locals {
}

module "ingestion" {
source = "../lambdas/ingestion"
storage_bucket_name = local.storage_bucket_name
lambda_vpc_security_group_ids = [
aws_security_group.lambda_egress_all_sg.id,
]
lambda_vpc_subnet_ids = module.vpc.public_subnets
source = "../lambdas/ingestion"
lambda_function_name = local.ingestion_lambda_name
lambda_repository_name = var.ingestion_repository_name

// S3
storage_bucket_name = local.storage_bucket_name
queue_name = local.queue_name

// VPC
lambda_vpc_security_group_ids = [aws_security_group.lambda_egress_all_sg.id]
lambda_vpc_subnet_ids = module.vpc.public_subnets

// RDS
pg_vector_host = aws_db_instance.vector_db.address
pg_vector_port = aws_db_instance.vector_db.port
pg_vector_database = aws_db_instance.vector_db.db_name
pg_vector_user = aws_db_instance.vector_db.username
pg_vector_password_secret_name = aws_secretsmanager_secret.password.name
secret_arn = aws_secretsmanager_secret.password.arn
lambda_repository_name = var.ingestion_repository_name
lambda_function_name = local.ingestion_lambda_name
queue_name = local.queue_name
}

module "inference" {
source = "../lambdas/inference"
lambda_vpc_security_group_ids = [
aws_security_group.lambda_egress_all_sg.id,
]
lambda_vpc_subnet_ids = module.vpc.public_subnets
pg_vector_host = aws_db_instance.vector_db.address
pg_vector_port = aws_db_instance.vector_db.port
pg_vector_database = aws_db_instance.vector_db.db_name
pg_vector_user = aws_db_instance.vector_db.username
pg_vector_password_secret_name = aws_secretsmanager_secret.password.name
secret_arn = aws_secretsmanager_secret.password.arn
lambda_repository_name = var.inference_repository_name
lambda_function_name = local.inference_lambda_name
memory_lambda_name = local.memory_lambda_name
dynamo_history_table_name = local.dynamo_history_table_name
embedding_collection_name = local.storage_bucket_name
source = "../lambdas/inference"
lambda_function_name = local.inference_lambda_name
lambda_repository_name = var.inference_repository_name

// VPC
lambda_vpc_security_group_ids = [aws_security_group.lambda_egress_all_sg.id]
lambda_vpc_subnet_ids = module.vpc.public_subnets

// RDS
pg_vector_host = aws_db_instance.vector_db.address
pg_vector_port = aws_db_instance.vector_db.port
pg_vector_database = aws_db_instance.vector_db.db_name
pg_vector_user = aws_db_instance.vector_db.username
pg_vector_password_secret_name = aws_secretsmanager_secret.password.name
secret_arn = aws_secretsmanager_secret.password.arn

// RAG
memory_lambda_name = local.memory_lambda_name
dynamo_history_table_name = local.dynamo_history_table_name
embedding_collection_name = local.storage_bucket_name

// API Gateway
api_gateway_rest_api_id = aws_api_gateway_rest_api.this.id
api_gateway_rest_api_root_resource_id = aws_api_gateway_rest_api.this.root_resource_id

stage_name = aws_api_gateway_stage.this.stage_name
}

module "memory" {
source = "../lambdas/conversation_memory"
lambda_vpc_security_group_ids = [
aws_security_group.lambda_egress_all_sg.id,
]
lambda_vpc_subnet_ids = module.vpc.public_subnets
aws_region = var.aws_region
lambda_function_name = local.memory_lambda_name
lambda_repository_name = var.memory_repository_name
source = "../lambdas/conversation_memory"
lambda_function_name = local.memory_lambda_name
lambda_repository_name = var.memory_repository_name

// VPC
lambda_vpc_security_group_ids = [aws_security_group.lambda_egress_all_sg.id]
lambda_vpc_subnet_ids = module.vpc.public_subnets

aws_region = var.aws_region

// RAG
dynamo_history_table_name = local.dynamo_history_table_name
}

module "list_collections" {
source = "../lambdas/list_collections"
lambda_repository_name = var.list_collections_repository_name
lambda_vpc_security_group_ids = [
aws_security_group.lambda_egress_all_sg.id,
]
lambda_vpc_subnet_ids = module.vpc.public_subnets
lambda_function_name = local.list_collections_lambda_name
aws_region = var.aws_region
pg_vector_host = aws_db_instance.vector_db.address
pg_vector_port = aws_db_instance.vector_db.port
pg_vector_database = aws_db_instance.vector_db.db_name
pg_vector_user = "collection_embedding_reader"
source = "../lambdas/list_collections"
lambda_function_name = local.list_collections_lambda_name
lambda_repository_name = var.list_collections_repository_name

// VPC
lambda_vpc_security_group_ids = [aws_security_group.lambda_egress_all_sg.id]
lambda_vpc_subnet_ids = module.vpc.public_subnets

aws_region = var.aws_region

// RDS
pg_vector_host = aws_db_instance.vector_db.address
pg_vector_port = aws_db_instance.vector_db.port
pg_vector_database = aws_db_instance.vector_db.db_name
pg_vector_user = "collection_embedding_reader"

// API Gateway
api_gateway_rest_api_id = aws_api_gateway_rest_api.this.id
api_gateway_rest_api_root_resource_id = aws_api_gateway_rest_api.this.root_resource_id
}

module "lex_router" {
source = "../lambdas/lex_router"
lambda_vpc_security_group_ids = [
aws_security_group.lambda_egress_all_sg.id,
]
lambda_vpc_subnet_ids = module.vpc.public_subnets
lambda_repository_name = var.lex_router_repository_name
source = "../lambdas/lex_router"
lambda_function_name = local.lex_router_lambda_name
lambda_repository_name = var.lex_router_repository_name
aws_region = var.aws_region
intent_lambda_mapping = {

// VPC
lambda_vpc_security_group_ids = [aws_security_group.lambda_egress_all_sg.id]
lambda_vpc_subnet_ids = module.vpc.public_subnets

// ENV VARS
intent_lambda_mapping = {
SelectCollection = local.list_collections_lambda_name
Inference = local.inference_lambda_name
}
Expand Down
10 changes: 5 additions & 5 deletions terraform/modules/api_gateway/lambda_integration/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "aws_api_gateway_resource" "api_gateway_resource" {
resource "aws_api_gateway_resource" "this" {
rest_api_id = var.api_gateway_rest_api_id
parent_id = var.api_gateway_rest_api_root_resource_id
path_part = var.api_gateway_path_part
Expand All @@ -9,20 +9,20 @@ module "cors" {
version = "0.3.3"

api_id = var.api_gateway_rest_api_id
api_resource_id = aws_api_gateway_resource.api_gateway_resource.id
api_resource_id = aws_api_gateway_resource.this.id
}

resource "aws_api_gateway_method" "api_gateway_method" {
rest_api_id = var.api_gateway_rest_api_id
resource_id = aws_api_gateway_resource.api_gateway_resource.id
resource_id = aws_api_gateway_resource.this.id
http_method = var.api_gateway_http_method
authorization = "NONE"
api_key_required = true
}

resource "aws_api_gateway_integration" "api_gateway_integration" {
rest_api_id = var.api_gateway_rest_api_id
resource_id = aws_api_gateway_resource.api_gateway_resource.id
resource_id = aws_api_gateway_resource.this.id
http_method = aws_api_gateway_method.api_gateway_method.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
Expand All @@ -38,4 +38,4 @@ resource "aws_lambda_permission" "lambda_permission" {
source_arn = "arn:aws:execute-api:${var.aws_region}:${data.aws_caller_identity.current.account_id}:${var.api_gateway_rest_api_id}/*/${aws_api_gateway_method.api_gateway_method.http_method}${aws_api_gateway_resource.api_gateway_resource.path}"
}

data "aws_caller_identity" "current" {}
data "aws_caller_identity" "current" {}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ variable "lambda_function_name" {
variable "aws_region" {
type = string
default = "us-east-1"
}
}

0 comments on commit a06f88d

Please sign in to comment.