From c58cfee0b631eb699b3ebda5dc5eb3c191473991 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 12 Mar 2026 10:41:08 +0000 Subject: [PATCH] upload zip to s3 rather than copying via api --- infrastructure/terraform/lambda/fast-api/main.tf | 1 + .../terraform/modules/lambda_service_zip/main.tf | 8 ++++++-- .../modules/lambda_service_zip/variables.tf | 7 +++++-- .../modules/lambda_with_api_gateway/main.tf | 13 ++++++++++++- .../modules/lambda_with_api_gateway/variables.tf | 3 ++- infrastructure/terraform/shared/main.tf | 6 ------ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/infrastructure/terraform/lambda/fast-api/main.tf b/infrastructure/terraform/lambda/fast-api/main.tf index c9058fb7..9e8c7c2b 100644 --- a/infrastructure/terraform/lambda/fast-api/main.tf +++ b/infrastructure/terraform/lambda/fast-api/main.tf @@ -82,6 +82,7 @@ module "fastapi" { runtime = "python3.11" timeout = 600 memory_size = 512 + artifact_bucket = data.terraform_remote_state.shared.outputs.ara_fast_api_state_bucket # domain_name = "api.${var.domain_name}" # certificate_arn = data.aws_ssm_parameter.certificate_arn.value diff --git a/infrastructure/terraform/modules/lambda_service_zip/main.tf b/infrastructure/terraform/modules/lambda_service_zip/main.tf index 285aa9d4..232b5b56 100644 --- a/infrastructure/terraform/modules/lambda_service_zip/main.tf +++ b/infrastructure/terraform/modules/lambda_service_zip/main.tf @@ -2,7 +2,7 @@ resource "aws_lambda_function" "this" { function_name = var.name role = var.role_arn package_type = "Zip" - filename = var.filename + # filename = var.filename source_code_hash = var.source_code_hash handler = var.handler runtime = var.runtime @@ -10,6 +10,10 @@ resource "aws_lambda_function" "this" { memory_size = var.memory_size publish = true + s3_bucket = var.s3_bucket + s3_key = var.s3_key + source_code_hash = var.source_code_hash + environment { variables = var.environment } @@ -21,4 +25,4 @@ output "lambda_arn" { output "function_name" { value = aws_lambda_function.this.function_name -} \ No newline at end of file +} diff --git a/infrastructure/terraform/modules/lambda_service_zip/variables.tf b/infrastructure/terraform/modules/lambda_service_zip/variables.tf index 68a35370..85d1f548 100644 --- a/infrastructure/terraform/modules/lambda_service_zip/variables.tf +++ b/infrastructure/terraform/modules/lambda_service_zip/variables.tf @@ -1,6 +1,6 @@ variable "name" { type = string } variable "role_arn" { type = string } -variable "filename" { type = string } +# variable "filename" { type = string } variable "source_code_hash" { type = string } variable "handler" { type = string } variable "runtime" { type = string } @@ -15,4 +15,7 @@ variable "memory_size" { variable "environment" { type = map(string) default = {} -} \ No newline at end of file +} +variable "s3_bucket" { type = string } +variable "s3_key" { type = string } +variable "source_code_hash" { type = string } \ No newline at end of file diff --git a/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf b/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf index 61e24c32..2277dee5 100644 --- a/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf +++ b/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf @@ -16,6 +16,16 @@ data "archive_file" "this" { excludes = var.zip_excludes } +############################################ +# Upload zip to S3 +############################################ +resource "aws_s3_object" "lambda_zip" { + bucket = var.artifact_bucket + key = "${var.name}-${var.stage}.zip" + source = data.archive_file.this.output_path + etag = data.archive_file.this.output_md5 +} + ############################################ # Lambda ############################################ @@ -24,7 +34,8 @@ module "lambda" { name = "${var.name}-${var.stage}" role_arn = module.role.role_arn - filename = data.archive_file.this.output_path + s3_bucket = var.artifact_bucket + s3_key = aws_s3_object.lambda_zip.key source_code_hash = data.archive_file.this.output_base64sha256 handler = var.handler runtime = var.runtime diff --git a/infrastructure/terraform/modules/lambda_with_api_gateway/variables.tf b/infrastructure/terraform/modules/lambda_with_api_gateway/variables.tf index ba2d844e..0b1dfe71 100644 --- a/infrastructure/terraform/modules/lambda_with_api_gateway/variables.tf +++ b/infrastructure/terraform/modules/lambda_with_api_gateway/variables.tf @@ -33,4 +33,5 @@ variable "certificate_arn" { variable "route53_zone_id" { type = string default = null -} \ No newline at end of file +} +variable "artifact_bucket" { type = string } \ No newline at end of file diff --git a/infrastructure/terraform/shared/main.tf b/infrastructure/terraform/shared/main.tf index 1e88435d..8a4e4a1f 100644 --- a/infrastructure/terraform/shared/main.tf +++ b/infrastructure/terraform/shared/main.tf @@ -530,12 +530,6 @@ module "ara_fast_api_state_bucket" { bucket_name = "ara-fast-api-terraform-state" } -module "ara_fastapi_registry" { - source = "../modules/container_registry" - name = "ara-fastapi" - stage = var.stage -} - # S3 policy for FastAPI app to read and write from various S3 buckets module "fast_api_s3_read_and_write" { source = "../modules/s3_iam_policy"