我正在尝试引用我使用 npm pack 创建并为 lambda 模块构建的现有源文件。当我尝试使用local_existing_package
时,我收到来自 lambda 模块的错误,就好像它试图从 s3 容器与本地查找 source.zip 文件一样。这个错误是由 lambda 模块本身产生的
错误:
│ 12: s3_key = var.s3_existing_package != null ? lookup(var.s3_existing_package, "key", null) : (var.store_on_s3 ? var.s3_prefix != null ? format("%s%s", var.s3_prefix, replace(local.archive_filename, "/^.*//", "")) : replace(local.archive_filename, "/^\\.//", "") : null)
│ ├────────────────
│ │ local.archive_filename is null
生成的 lambda 模块中的代码:
locals {
archive_filename = element(concat(data.external.archive_prepare.*.result.filename, [null]), 0)
archive_was_missing = element(concat(data.external.archive_prepare.*.result.was_missing, [false]), 0)
# Use a generated filename to determine when the source code has changed.
# filename - to get package from local
filename = var.local_existing_package != null ? var.local_existing_package : (var.store_on_s3 ? null : local.archive_filename)
was_missing = var.local_existing_package != null ? !fileexists(var.local_existing_package) : local.archive_was_missing
# s3_* - to get package from S3
s3_bucket = var.s3_existing_package != null ? lookup(var.s3_existing_package, "bucket", null) : (var.store_on_s3 ? var.s3_bucket : null)
s3_key = var.s3_existing_package != null ? lookup(var.s3_existing_package, "key", null) : (var.store_on_s3 ? var.s3_prefix != null ? format("%s%s", var.s3_prefix, replace(local.archive_filename, "/^.*//", "")) : replace(local.archive_filename, "/^\\.//", "") : null)
s3_object_version = var.s3_existing_package != null ? lookup(var.s3_existing_package, "version_id", null) : (var.store_on_s3 ? element(concat(aws_s3_bucket_object.lambda_package.*.version_id, [null]), 0) : null)
我引用 ^^ 的模块定义为:
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"
# using prepackaged zip vs source
#https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws/latest#lambda-functions-with-existing-package-prebuilt-stored-locally
# prebuilt packaging
create_package = false
local_existing_package = "${path.module}/../source.zip"
store_on_s3 = true
s3_bucket = module.s3_bucket.s3_bucket_id
我在这个模块上查看了来自 github 的示例,它看起来与推荐的内容相匹配。
谁能提供一个如何链接源文件的例子或指出我缺少什么?这是使用 terraform 0.13.4 构建的