创建两个Lambda函数时遇到问题。我的“控制器”功能部署没有问题,但是我的“块”功能抛出了一个错误“错误:环境中至少应该有一个字段”
这两个功能几乎相同,但zip文件和环境变量不同。
function_name = format("ancb-chunker-%s",var.env)
s3_bucket = aws_s3_bucket.ancb["lambda"].id
s3_key = var.lambda_zip_chunker
handler = "handler.chunker"
runtime = "nodejs8.10"
role = aws_iam_role.lambda_exec.arn
environment {
variables = {
TEST = "yes"
ORIGINAL_BUCKET = aws_s3_bucket.ancb["original"].id
TO_PROCESS_BUCKET = aws_s3_bucket.ancb["to-process-prod"].id
ENVIRONMENT = var.env
CHUNK_SIZE = 5000
}
}
tags = {
Environment = var.env
Terraform = true
}
}
resource "aws_lambda_function" "ancb_controller" {
function_name = format("ancb-controller-%s",var.env)
s3_bucket = aws_s3_bucket.ancb["lambda"].id
s3_key = var.lambda_zip_controller
handler = "handler.controller"
runtime = "nodejs8.10"
role = aws_iam_role.lambda_exec.arn
environment {
variables = {
DESTINATION_BUCKET = aws_s3_bucket.ancb["destination"].id
ENVIRONMENT = var.env
ERROR_BUCKET = aws_s3_bucket.ancb["error"].id
GEOCODIO_APIKEY = <removed>
GEOCODIO_ENDPOINT = <removed>
GEOCODIO_VERSION = "v1.3"
ORIGINAL_BUCKET = aws_s3_bucket.ancb["original"].id
SOURCE_BUCKET = aws_s3_bucket.ancb["source"].id
TO_PROCESS_BUCKET = aws_s3_bucket.ancb["to-process"].id
WORKING_BUCKET = aws_s3_bucket.ancb["working"].id
}
}
tags = {
Environment = var.env
Terraform = true
}
}
这是收到的错误:
Error: At least one field is expected inside environment
on .terraform/modules/ancb/services/ancb/main.tf line 29, in resource "aws_lambda_function" "ancb_chunker":
29: resource "aws_lambda_function" "ancb_chunker" {
我希望代码对两者都起作用,但是在测试中,为“块”设置的环境变量不起作用。如果将“控制器”的环境变量放在“块”变量中,则可以毫无问题地创建函数...
答案 0 :(得分:0)
Lambda不需要设置任何环境变量。
但是,您正在传递var.env,却不了解您的更多问题,我会在这里查看。
答案 1 :(得分:0)
这个问题是我的错误。.处理桶不存在,而是需要是[“ to-process”] TO_PROCESS_BUCKET = aws_s3_bucket.ancb [“ to-process-prod”]。id。
很抱歉浪费大家的时间。