简体   繁体   中英

AWS Eventbridge rule trigger once all in-flight sqs messages are processed

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM