Reputation: 999
I am having a problem with my terraform. my lambda is expecting a specific format of message from CloudWatch event rule
resource "aws_cloudwatch_event_rule" "send_hello" {
name = "say-hi"
schedule_expression = "cron(0/5 * * * *)"
is_enabled = true
event_pattern = <<PATTERN
{
"who": "Peter",
"message_part_1": "hello",
"message_part_2": "this is the world"
}
PATTERN
}
I am getting
"who" must be an object or array
my lambda needs to receive an event of
{
"who": "Peter",
"message_part_1": "hello",
"message_part_2": "this is the world"
}
how should I format my event pattern?
ADDITIONAL: the following changes do create the resource, but there is no "who" or "message" in the event when the rule calls lambda
resource "aws_cloudwatch_event_rule" "send_hello" {
name = "say-hi"
schedule_expression = "cron(0/5 * * * *)"
is_enabled = true
event_pattern = <<PATTERN
{
"who": ["Peter"],
"message_part_1": ["hello"],
"message_part_2": ["this is the world"]
}
PATTERN
}
Upvotes: 2
Views: 1474
Reputation: 238887
Your send_hello
works on schedule, thus event_pattern
does not apply. If you want to pass something to your lambda on schedule, you have to specify input_template of your aws_cloudwatch_event_target
instead:
Template to customize data sent to the target. Must be valid JSON.
Upvotes: 1