【发布时间】:2022-01-10 21:07:53
【问题描述】:
我正在尝试通过 terraform 为 gitlab 存储库中存在的文件创建 lambda 函数,但是我在 CICD 管道中遇到错误:
"./lambda_function.zip: 没有这样的文件或目录"
包含 lambda 函数 python 文件的文件夹(src 文件夹)与包含 terraform 文件的文件夹(terraform)不同。
我的 Gitlab 项目看起来像
项目名称
-src
- lambda_function.py
-地形
- lambda.tf
而 lambda.tf 中的 terraform 代码是:
data "archive_file" "lambda" {
type = "zip"
source_file = "../src/lambda_function.py"
output_path = "lambda_function.zip"
}
resource "aws_lambda_function" "automation-lambda"
{filename=data.archive_file.lambda.output_path
description = "Creating lambda"
function_name = "lambda_fx"
role = "xxxxxxxxxxxxx"
handler = "lambda_function.lambda_handler"
memory_size = 128
timeout = 300
source_code_hash = data.archive_file.lambda.output_base64sha256
runtime = "python3.7"
}
请建议如何解决该问题。
谢谢
【问题讨论】:
-
我也收到此错误,在本地可以正常工作,但在管道中显示“无法加载
”:打开 : no such file 或目录 -
解决方案:
locals { source_files = ["../src/ingestion/ingestion.py"] } data "template_file" "t_file" { count = length(local.source_files) template = file(element(local.source_files, count.index)) } resource "local_file" "to_temp_dir" { count = length(local.source_files) filename = "${path.module}/temp/${basename(element(local.source_files, count.index))}" content = element(data.template_file.t_file.*.rendered, count.index) } -
data "archive_file" "lambda_function_archive" { type = "zip" source_dir = "${path.module}/temp" output_path = "${path.module}/abc.zip" depends_on = [ local_file.to_temp_dir, ] }
标签: amazon-web-services aws-lambda gitlab-ci terraform-provider-aws