23

In Amazon Web Services (AWS) Eventbridge, I can create cron-style scheduled rules to fire an event regularly.

When I'm creating or editing these, I often want to test that they work immediately (rather than waiting until the next scheduled execution). For testing purposes, triggering the rule's target manually is not always equivalent to the rule running (perhaps because a template is used to customise the event JSON).

Is there an easy way of triggering a AWS EventBridge scheduled job to run immediately, via the user interface or via the command line?

I generally do this by modifying the cron schedule to two minutes in the future, then reverting it, but this is tedious and error prone. Perhaps there's an obvious button I've failed to see, or else a cli command that I haven't found (e.g. at https://awscli.amazonaws.com/v2/documentation/api/latest/reference/events/index.html#cli-aws-events).

phhu
  • 1,462
  • 13
  • 33
  • Short of a "test rule" button in EventBridge, two solutions I can think of are: (i) use an intermediate lambda: EventBridge triggers a lambda, and the lambda triggers the target. Then the lambda can be tested using the normal lambda test functionality, and EventBridge only needs permissions to start the lambda, hopefully meaning less can go wrong. (ii) use the AWS CLI to modified the EventBridge rule's scheduled start time to the near future (and optionally to reset it to some previous value). – phhu Apr 22 '22 at 10:02
  • A rule runs when some condition is met. For cron rules, the condition is time. Testing a cron rule by manually triggering it wouldn't make sense - your cron schedule could be totally wrong. If you're wanting to test if event bridge works, well, it does. You can create a one time schedule as @kushan-gunasekera mentioned if you want to see what the event body looks like. – akerra Jun 07 '23 at 20:19
  • "manually triggering it wouldn't make sense - your cron schedule could be totally wrong": yes, but it's also possible that a the rule might have a mistake in it not related to the cron schedule, especially if the rule has been changed, and it's this kind of error I'm wanting to test for. (With cron on a linux machine, I might copy the command from the cron table to a terminal and run it manually (as appropriate user etc), which is quick, and catches a good number of my errors, or else use cron to trigger a script - a bit like using a lambda... AWS lambda does have good testing functionality) – phhu Jun 08 '23 at 13:47
  • ...otherwise put, I want to test that everything works EXCEPT the cron time condition - and this is most reliable when the distance in configuration space (or hassle space) between what the cron rule does (/triggers) and what is tested is as small as possible – phhu Jun 08 '23 at 13:50

1 Answers1

0

Trigger it every 5 minutes and you'll see it triggered a few times. Later change the cron schedule.

Adwait Mathkari
  • 116
  • 1
  • 5
  • That works, but it's more or less the workaround I described in the question ("I generally do this by modifying the cron schedule to two minutes in the future, then reverting it, but this is tedious and error prone. ").... I'm looking for a means of testing it without changing the schedule, and without the inconvenience of having to wait for it to trigger (compare with AWS Lambda's testing functionality, which works well like this). – phhu Aug 17 '23 at 14:43