aws-lambda - 使用 terraform 部署多个 lambda 函数
问题描述
由于此SO Answer,请勿将此标记为重复
我有一个“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}"))}"
}
确保它们具有不同的函数名称
推荐阅读
- java - REST:具有不同条件参数的资源的相同端点
- swiftui - SwiftUi - 为 MapKit 构建微调器
- python - 如何在 Swagger UI 中对 FastAPI 端点进行分组?
- java - 优先级队列作为最大优先级队列未按预期工作
- php - PHP strtotime 不包括元旦...如何包括假期?
- python - 是否可以在 python 中切片多维列表(不是 numpy)?
- python - 使用python插入方法挑战
- powershell - WMIC 查询 Creationdate 以查找旧进程
- python - 如何从 Python 中的站点获取随机图像链接?
- php - 如何在不更改登录参数的情况下解决“LOGINREC 字段的名称太长(严重性 2)”