mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
upload zip to s3 rather than copying via api
This commit is contained in:
parent
d45958843b
commit
c58cfee0b6
6 changed files with 26 additions and 12 deletions
|
|
@ -82,6 +82,7 @@ module "fastapi" {
|
||||||
runtime = "python3.11"
|
runtime = "python3.11"
|
||||||
timeout = 600
|
timeout = 600
|
||||||
memory_size = 512
|
memory_size = 512
|
||||||
|
artifact_bucket = data.terraform_remote_state.shared.outputs.ara_fast_api_state_bucket
|
||||||
|
|
||||||
# domain_name = "api.${var.domain_name}"
|
# domain_name = "api.${var.domain_name}"
|
||||||
# certificate_arn = data.aws_ssm_parameter.certificate_arn.value
|
# certificate_arn = data.aws_ssm_parameter.certificate_arn.value
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ resource "aws_lambda_function" "this" {
|
||||||
function_name = var.name
|
function_name = var.name
|
||||||
role = var.role_arn
|
role = var.role_arn
|
||||||
package_type = "Zip"
|
package_type = "Zip"
|
||||||
filename = var.filename
|
# filename = var.filename
|
||||||
source_code_hash = var.source_code_hash
|
source_code_hash = var.source_code_hash
|
||||||
handler = var.handler
|
handler = var.handler
|
||||||
runtime = var.runtime
|
runtime = var.runtime
|
||||||
|
|
@ -10,6 +10,10 @@ resource "aws_lambda_function" "this" {
|
||||||
memory_size = var.memory_size
|
memory_size = var.memory_size
|
||||||
publish = true
|
publish = true
|
||||||
|
|
||||||
|
s3_bucket = var.s3_bucket
|
||||||
|
s3_key = var.s3_key
|
||||||
|
source_code_hash = var.source_code_hash
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
variables = var.environment
|
variables = var.environment
|
||||||
}
|
}
|
||||||
|
|
@ -21,4 +25,4 @@ output "lambda_arn" {
|
||||||
|
|
||||||
output "function_name" {
|
output "function_name" {
|
||||||
value = aws_lambda_function.this.function_name
|
value = aws_lambda_function.this.function_name
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
variable "name" { type = string }
|
variable "name" { type = string }
|
||||||
variable "role_arn" { type = string }
|
variable "role_arn" { type = string }
|
||||||
variable "filename" { type = string }
|
# variable "filename" { type = string }
|
||||||
variable "source_code_hash" { type = string }
|
variable "source_code_hash" { type = string }
|
||||||
variable "handler" { type = string }
|
variable "handler" { type = string }
|
||||||
variable "runtime" { type = string }
|
variable "runtime" { type = string }
|
||||||
|
|
@ -15,4 +15,7 @@ variable "memory_size" {
|
||||||
variable "environment" {
|
variable "environment" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
default = {}
|
default = {}
|
||||||
}
|
}
|
||||||
|
variable "s3_bucket" { type = string }
|
||||||
|
variable "s3_key" { type = string }
|
||||||
|
variable "source_code_hash" { type = string }
|
||||||
|
|
@ -16,6 +16,16 @@ data "archive_file" "this" {
|
||||||
excludes = var.zip_excludes
|
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
|
# Lambda
|
||||||
############################################
|
############################################
|
||||||
|
|
@ -24,7 +34,8 @@ module "lambda" {
|
||||||
|
|
||||||
name = "${var.name}-${var.stage}"
|
name = "${var.name}-${var.stage}"
|
||||||
role_arn = module.role.role_arn
|
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
|
source_code_hash = data.archive_file.this.output_base64sha256
|
||||||
handler = var.handler
|
handler = var.handler
|
||||||
runtime = var.runtime
|
runtime = var.runtime
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,5 @@ variable "certificate_arn" {
|
||||||
variable "route53_zone_id" {
|
variable "route53_zone_id" {
|
||||||
type = string
|
type = string
|
||||||
default = null
|
default = null
|
||||||
}
|
}
|
||||||
|
variable "artifact_bucket" { type = string }
|
||||||
|
|
@ -530,12 +530,6 @@ module "ara_fast_api_state_bucket" {
|
||||||
bucket_name = "ara-fast-api-terraform-state"
|
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
|
# S3 policy for FastAPI app to read and write from various S3 buckets
|
||||||
module "fast_api_s3_read_and_write" {
|
module "fast_api_s3_read_and_write" {
|
||||||
source = "../modules/s3_iam_policy"
|
source = "../modules/s3_iam_policy"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue