Skip to content

Combining a Rate and an Event Pattern into a single Event Bridge rule

0

Here's my usecase: I have two AWS batch jobs: A & B What I would like to do is when batch job A completes successfully, it then triggers Step Function B to start execution every 1 minute until midnight. Then the next day the cycle starts again with Batch Job A. How is this possible in AWS Batch? Is there an alternative solution available? This is possible in BMC Control-M but it seems it might not be possible in AWS.

asked 8 months ago131 views
1 Answer
0

While it's not possible to directly combine a rate expression and an event pattern into a single EventBridge rule in AWS, you can achieve your desired outcome using a combination of AWS services. Here's an approach to accomplish what you're looking for:

  1. Create an EventBridge rule that triggers when Batch job A completes successfully. This rule would use an event pattern to match the "Batch Job State Change" event with a "SUCCEEDED" status for job A.

  2. Set the target of this rule to be an AWS Step Functions state machine.

  3. Design the Step Functions state machine to do two things: a. Start Batch job B b. Use a Wait state with a "SecondsPath" of 60 seconds (1 minute)

  4. After the Wait state, use a Choice state to check if a certain condition is met (e.g., a maximum number of iterations or a specific time has passed).

  5. If the condition is not met, loop back to start Batch job B again. If the condition is met, end the execution.

This solution allows you to:

  • Trigger the process when Batch job A completes successfully
  • Start Batch job B every minute
  • Control how long this process continues

While this approach doesn't use a single EventBridge rule with both a rate and an event pattern, it achieves the desired outcome using AWS services. It provides more flexibility and control over the process compared to a simple rate-based rule.

If you need to adjust the frequency or duration of the repeated executions, you can easily modify the Wait state in the Step Functions state machine. This solution also allows you to add additional logic or error handling as needed within the state machine.

Remember to set up appropriate IAM roles and permissions for EventBridge to trigger Step Functions, and for Step Functions to start AWS Batch jobs.
Sources
Tutorial: Create a rule with an event pattern - AWS Batch
Tutorial: Register the event rule - AWS Batch
aws-eventbridge-stepfunctions - AWS Solutions Constructs

answered 8 months ago
EXPERT
reviewed 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.