You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Terraform AWS Lambda模块引用本地打包的源文件

问题根因

你同时配置了store_on_s3 = true和create_package = false,该版本Lambda模块的local_existing_package参数默认仅在不使用S3存储的场景下生效。当store_on_s3开启时,模块会强制走S3部署逻辑,需要用到打包流程生成的local.archive_filename变量拼接S3对象键,而你设置create_package = false禁用了所有包处理流程,导致该变量为空,触发报错。


解决方法

方案1:直接使用本地包部署(不存S3)

调整配置关闭S3存储逻辑即可,修改后的配置如下:

module "my_lambda_fn" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "~>2.17.0"

  function_name = "my-api-fn"
  description   = "Function for example"
  handler       = "src/index.handler"
  runtime       = "nodejs14.x"
  timeout       = 10
  memory_size   = 512
  publish       = true
  cloudwatch_logs_retention_in_days = 60
  attach_tracing_policy = true
  tracing_mode          = "Active"

  # 预打包本地包配置
  create_package         = false
  local_existing_package = "${path.module}/../source.zip"

  # 关闭S3存储,直接读取本地包部署
  store_on_s3 = false
}

方案2:需要将本地包上传到S3再部署

如果场景要求必须把部署包存在S3,不需要设置create_package = false,模块会自动识别本地预打包文件、跳过源码打包步骤直接上传到S3,修改后的配置如下:

module "my_lambda_fn" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "~>2.17.0"

  function_name = "my-api-fn"
  description   = "Function for example"
  handler       = "src/index.handler"
  runtime       = "nodejs14.x"
  timeout       = 10
  memory_size   = 512
  publish       = true
  cloudwatch_logs_retention_in_days = 60
  attach_tracing_policy = true
  tracing_mode          = "Active"

  # 预打包本地包配置
  local_existing_package = "${path.module}/../source.zip"

  store_on_s3 = true
  s3_bucket   = module.s3_bucket.s3_bucket_id
}

内容的提问来源于stack exchange,提问作者rlcrews

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 06:27:03