我想配置 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
参数,该参数可以在调用 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
}