Ниже приведена конфигурация, которую я использовал для создания события cloudwatch для горячего обратного вызова с input_transformer.
resource "aws_cloudwatch_event_rule" "flask-apis-cloudwatch-terraform" {
name = "warm_call_back_flask_apis"
description = "Keep Warm Callback function for flask-apis"
schedule_expression = "rate(4 minutes)"
role_arn = "${aws_iam_role.lambda_exec_flask.arn}"
}
resource "aws_cloudwatch_event_target" "flask-apis-cloudwatch-terraform-target" {
rule = "${aws_cloudwatch_event_rule.flask-apis-cloudwatch-terraform.name}"
target_id = "${aws_lambda_function.flask-apis.function_name}"
arn = "${aws_lambda_function.flask-apis.arn}"
input_transformer = {
input_paths = {"detail-type"="$.detail-type","resources"="$.resources","detail"="$.detail","id"="$.id","source"="$.source","time"="$.time","region"="$.region","version"="$.version","account"="$.account"}
input_template = <<INPUT_TEMPLATE_EOF
{
"time":<time>,
"detail-type": <detail-type>,
"source": <source>,
"account": <account>,
"region": <region>,
"detail": <detail>,
"version": <version>,
"resources": <resources>,
"id": <id>,
"kwargs": {}
}
INPUT_TEMPLATE_EOF
}
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_flask-apis" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.flask-apis.arn}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.flask-apis-cloudwatch-terraform.arn}"
}