aws_lambda_invocation >条件



我将一些值传递给lambda函数,然后调用它。它工作得很好。

我有几个相互依赖的,还有依赖链中的一些资源。

Invoke_1 > Invoke_2 > aws_glue_catalog_database > Invoke_3

然而,Lambda在每个计划中都被列为"已读",并在每次申请时执行。

首先,这使得该计划更难阅读。冗长的输出(列出我传递的所有值(意味着更难发现其他资源的真正变化。

其次,它运行的是一个不需要运行的函数,这不是clean

所以

有没有一种方法可以使这些调用成为有条件的,不会打乱我的依赖链?

// zips the python file in order to be used by lambda
data "archive_file" "lf_settings_1_zip" {
type        = "zip"
source_dir  = "${path.module}/scripts/lf_settings_s1/"
output_path = "${path.module}/scripts/s1deploy.zip"
}
resource "aws_lambda_function" "lakeformation_settings_1" {
function_name    = "dlsettings_1"
filename         = data.archive_file.lf_settings_1_zip.output_path
source_code_hash = data.archive_file.lf_settings_1_zip.output_base64sha256
role             = aws_iam_role.myRole.arn
handler          = "main.main"
runtime          = "python3.8"
}
locals {
lf1_json = <<JSON
{
"account":"${local.account_id}",
"principals":[
"arn:aws:iam::${local.account_id}:role/Role1",
"arn:aws:iam::${local.account_id}:role/Role2"
]
}
JSON
}
data "aws_lambda_invocation" "invo1" {
function_name = "dlsettings_1"
input         = local.lf1_json

depends_on = [
aws_lambda_invocation.invo0,
aws_lambda_function.lakeformation_settings_1
]
}

数据源仍然允许count参数。我不太确定你将如何用当前的地形代码实现它,但这就是想法。如果var.boolean_youcreate设置为false,则不会调用它:

data "aws_lambda_invocation" "example" {
count         = var.boolean_youcreate ? "1" : "0"
function_name = aws_lambda_function.lambda_function_test.function_name
input = <<JSON
{
"key1": "value1",
"key2": "value2"
}
JSON
}
output "result_entry" {
value = jsondecode(data.aws_lambda_invocation.example.result)["key1"]
}

相关内容

  • 没有找到相关文章

最新更新