5

I have two AWS-Lamdbda functions and I want Lambda A to determine a certain point in time like the 4. May 2022 10:00. Then I want Lambda B to be scheduled to run at this specific point in time.

I'm probably able to achieve this by programmatically creating a AWS eventbrigde rule with Lambda A and use the cron pattern to match my point in time. Inside of Lambda B I would then need to delete that rule, because it's for a one time use.

Can one of you think of a more elegant way to achieve this ?

Thanks you for your wisdom !

Edit:

My point in time is dynamic. I call a public API to find the point for Lambda B to run, so I can't use EventBridge directly. I plan on running Lambda A once a day to see if a new Lambda B run is necessary.

Ludi
  • 433
  • 2
  • 16
  • Why not using eventbrigde rule with Lambda B directly! – Youcef LAIDANI Mar 14 '22 at 12:30
  • I'm not sure what you mean by that? :( – Ludi Mar 14 '22 at 12:32
  • If lambda A is used to determine a point in time and based on this time you start lambda B, then I would suggest to use eventbridge to determine the time and based on this you call your lambda B, in another word, I think your Lambda A do the work of eventbridge! – Youcef LAIDANI Mar 14 '22 at 12:36
  • My point in time is dynamic. I call a public API to find the point for Lambda B to run, so I can't use EventBridge directly. I plan on running Lambda A once a day to see if a new Lambda B run in nessasary. – Ludi Mar 14 '22 at 12:49
  • Adding the same point @YCF_L mentioned. Please check this question answer https://stackoverflow.com/questions/71267867/how-to-set-a-cycle-for-an-aws-kinesis-timestream/71268024#71268024 – Jijo Alexander Mar 14 '22 at 13:06
  • How long is the wait between A determining the run-time and B running? Minutes, hours, days? And does B need to run _exactly_ at the run-time, or approximately? – fedonev Mar 14 '22 at 13:09
  • The difference is usually a few days up to 3 weeks maybe. The time needs to be very precise, but I'm planning to start the function a few minutes early and the have a python timer to do the exact timing. – Ludi Mar 14 '22 at 13:27

1 Answers1

9

[Edit Nov 2022]: EventBridge Scheduler

The new EventBridge Scheduler supports one-time schedules for events. The event will be invoked on the date and time you pass as the schedule expression: at(yyyy-mm-ddThh:mm:ss) in the boto3 EventScheduler client's create_schedule API.


Here are a few more options to schedule a Lambda run at an arbitrary point in time:

Step Function

A three-state Step Function orchestrates the two Lambdas. Lambda A obtains and outputs a timestamp. A Wait State waits until the timestamp passes. Then Lambda B runs.

This approach is precise. N.B. Standard Workflow executions have a duration up to one year, so they can accomodate long waits.

DynamoDB Streams + TTL

Create a DynamoDB table with a TTL field and Dynamo DB Streams enabled. Set Lambda B as the Streams processor. Lambda A writes a record to the table with the timestamp as TTL. Shortly after the TTL timestamp passes, DynamoDB will trigger Lambda B.

This approach won't give you the precision of the first approach, but will be cheaper if you have loads of events.

fedonev
  • 20,327
  • 2
  • 25
  • 34