gpt4 book ai didi

amazon-web-services - 配置 CloudWatch Events 以使用 Terraform 将输入发送到 Lambda 函数

转载 作者:行者123 更新时间:2023-12-04 13:17:04 24 4
gpt4 key购买 nike

我想配置 CloudWatch Events 以使用 Terraform 将输入发送到 Lambda 函数。
我已经使用以下脚本来做到这一点:

resource "aws_cloudwatch_event_rule" "aa-rule-event" {
count = "${var.count}"
name = "${var.application_name}-${element(var.names, count.index)}"
description = "${element(var.descriptions, count.index)}"
schedule_expression = "${element(var.cron-expressions, count.index)}"
is_enabled = "${element(var.rule-status-states, count.index)}"
}

resource "aws_cloudwatch_event_target" "aa-rule-target" {
count = "${var.count}"
rule = "${var.application_name}-${element(var.names, count.index)}"
target_id = "CloudWatchToLambda"
arn = "arn:aws:lambda:${var.aws_region}:${var.aws_account_number}:function:${var.application_name}-${element(var.target-lambda-function, count.index)}"
}

我需要通过此 CloudWatch 事件向目标 Lambda 提供输入。我知道可以配置输入,但如何在 Terraform 中配置它?

最佳答案

aws_cloudwatch_event_target资源需要一个可选的 input parameter可以在调用 Lambda 函数时将 JSON blob 传递给与负载等效的目标。

resource "aws_cloudwatch_event_rule" "aa-rule-event" {
count = "${var.count}"
name = "${var.application_name}-${element(var.names, count.index)}"
description = "${element(var.descriptions, count.index)}"
schedule_expression = "${element(var.cron-expressions, count.index)}"
is_enabled = "${element(var.rule-status-states, count.index)}"
}

resource "aws_cloudwatch_event_target" "aa-rule-target" {
count = "${var.count}"
rule = "${var.application_name}-${element(var.names, count.index)}"
target_id = "CloudWatchToLambda"
arn = "arn:aws:lambda:${var.aws_region}:${var.aws_account_number}:function:${var.application_name}-${element(var.target-lambda-function, count.index)}"
input = <<JSON
{
"foo": {
"bar": [
1,
2
]
}
}
JSON
}

关于amazon-web-services - 配置 CloudWatch Events 以使用 Terraform 将输入发送到 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59377850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com