由于此SO应答,请勿将其标记为重复
我有一个"aws_lambda_function"资源,它运行良好。
现在我想部署另一个lambda函数,我尝试用不同的处理程序和别名复制整个块,但它引发了一个错误。有其他方法吗?
提前谢谢。
更新
这是地形代码:
resource "aws_lambda_function" "api_service" {
function_name = "${substr("${local.api_artifact_name}", 0, min(64, length(local.api_artifact_name)))}"
# Artifacts bucket
s3_bucket = "${local.artifacts_bucket_name}"
s3_key = "${module.artifact-upload.artifact_key}"
# "index" is the filename within the zip file (main.js) and "handler"
# is the name of the property under which the handler function was
# exported in that file.
handler = "index.api"
runtime = "nodejs8.10"
role = "${module.api-service-iam.iam_role_arn}"
# Optional, but ensures that things don't constantly refresh during local development
source_code_hash = "${base64sha256(file("${local.api_dist_dir}"))}"
environment {
variables = {
...
}
}
}
现在资源api_service
成功地部署了一个Lambda函数,但我如何才能部署,比如说,5个这样的函数?
All these Lambda functions will be invoked by an API Gateway later.
所以基本上答案一直盯着我的脸。
我复制了整个资源块,并进行了以下更改:
resource "aws_lambda_function" "lambda-1" {
function_name = "lambda-1-${substr("${local.api_artifact_name}", 0, min(64, length(local.api_artifact_name)))}"
# Artifacts bucket
s3_bucket = "${local.artifacts_bucket_name}"
s3_key = "${module.artifact-upload.artifact_key}"
# "index" is the filename within the zip file (main.js) and "handler"
# is the name of the property under which the handler function was
# exported in that file.
handler = "lambda-1/index.api"
runtime = "nodejs8.10"
role = "${module.api-service-iam.iam_role_arn}"
# Optional, but ensures that things don't constantly refresh during local development
source_code_hash = "${base64sha256(file("${local.api_dist_dir}"))}"
}
resource "aws_lambda_function" "lambda-2" {
function_name = "lambda-2-${substr("${local.api_artifact_name}", 0, min(64, length(local.api_artifact_name)))}"
# Artifacts bucket
s3_bucket = "${local.artifacts_bucket_name}"
s3_key = "${module.artifact-upload.artifact_key}"
# "index" is the filename within the zip file (main.js) and "handler"
# is the name of the property under which the handler function was
# exported in that file.
handler = "lambda-2/index.api"
runtime = "nodejs8.10"
role = "${module.api-service-iam.iam_role_arn}"
# Optional, but ensures that things don't constantly refresh during local development
source_code_hash = "${base64sha256(file("${local.api_dist_dir}"))}"
}
确保它们有不同的函数名
我基本上为每个lambda创建一个目录,并为policy.json、ssm_parameters.json等工件使用命名约定。
1( 我使用外部数据源来获取目录中的lambda函数列表,并获取每个lambda所需的所有元数据2( 我使用count="N"来部署每个lambda资源。