8

I've understood AWS Cloudwatch Scheduled Rules (Amazon EventBridge Rules) which works by defining CRON expression.

The documentation mentions rules that triggers repetitively on a given time. Such as, run a Cloudwatch rule every 15 mins and so on.

What I want is a Rule that runs only ONCE. Any ways to achieve it? For example, run a rule after 1 hour from now, and thereafter it should never run.

Any solution?

PS: I've checked event based rule also but I don't have any event that can trigger rule.

Tejaskumar
  • 754
  • 8
  • 24
  • You can make your code create a cloudwatch rule that runs every hour and then on the first trigger delete that rule again. – luk2302 Mar 02 '21 at 12:53
  • what actually that target for that Rule? if it's one time, perhaps we can directly trigger that target rather than having a rule? – Balu Vyamajala Mar 02 '21 at 13:07

2 Answers2

10

You can use a CRON expression in CloudWatch Events (or EventBridge) that only specifies one point in time by simply not using wildcards/repeats in the CRON expression.

For example, run a rule after 1 hour from now, and thereafter it should never run.

While you cannot directly express "one hour from now on" in a CRON expression, you can build a CRON expression that will specify that absolute point in time, such as:

cron(0 15 2 3 ? 2021)

if today were the second of March 2021, at 14:00 o'clock. So, this is the CRON expression you'd use to say "one hour from now".

httpdigest
  • 5,411
  • 2
  • 14
  • 28