Reputation: 514
I want to fire off a Lambda when all in-flight messages on my SQS queue are processed. I can't find much on Terraform's documentation. Thoughts? I have most of the terraform complete.
resource "aws_cloudwatch_event_rule" "start_after_in_flight_rule" {
name = "start-after-in-flight"
*Insert rule here**************
}
resource "aws_cloudwatch_event_target" "start_process_target_in_flight" {
arn = aws_lambda_function.some_lambda_I_want_to_run.arn
rule = aws_cloudwatch_event_rule.start_after_in_flight_rule.id
input = <<JSON
{
"param1": "1",
"param2": "2"
}
JSON
}
resource "aws_lambda_permission" "event-invoke-start-process" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.some_lambda_I_want_to_run.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.start_after_in_flight_rule.arn
}
Upvotes: 0
Views: 719
Reputation: 238051
I can't find much on Terraform's documentation.
You can't find any information about that, because there is no such functionality in TF nor even in AWS. You need a custom solution for that. This may include setting an alarm on SQS metrics to monitor the number of messages, and triggering the alarm when its empty. Or having some lambda function periodically checking the SQS queue for number of messages, and then triggering some other action.
Upvotes: 3