Here is my use case:
I have a scheduler
lamdba and a executor
lambda.
In the scheduler
lambda, I receive a list of (time, message)
tuples indicating that, at time
I would like to invoke the executor
lambda with event message
.
Here is what I have tried
- In the
scheduler
lambda, first clear all triggers from theexecutor
lambda. Then create a EventBridge scheduled event for each(time, message)
tuple. This has a few drawbacks...- It's quite difficult to remove all triggers from a lambda, as the Lambda API doesn't let you do that (I believe I have to do it through the EventBridge API with proper tagging)
- Adding and removing ~100 triggers every day seems uneconomical and is not the intended use case of event bridge
- Running a dedicated EC2 instance to call the lambda function
- I'm cheap and I don't want to pay for an instance that will lay idle for ~99.9% of the time.
- Not serverless
Is there a serverless way of trigger a lambda in a non-periodic fashion?
A bit of a departure, but could you use dynamodb with a ttl? The scheduler could simply write to the table with the message, and format the ttl column to expire at the time you're adding to the tuple.
You could subscribe the executor lambda to the DynamoDb events, and only respond to events that are removed, and if you use
New and old images
you can retrieve the message from the old image (otherwise I believe it's empty when the item is deleted).