Question for the experts here, I want to create a job scheduling application that relies on a lambda function, at invocation it will do specific things based on inputs which is all wrapped up in the image (at this time do x, at that time do y, etc)
currently i use eventbridge to schedule when the various jobs are triggered with various input, this works fine when the number of jobs/invocations are small, 10-20 but it gets annoying if i had say 500 different jobs to run. my thought was that instead of triggering my lambda function at discrete eventbrige cronlike times, i create a function that runs every minute, and then store the various parameters/inputs in a db somewhere, and at each invocation ti would call the db, check if it needs to do something and do it, or just die and wait for the next minute. to me this is kind of replicating how crond works.
is that the best way? is there some other best practice for managing a large load of jobs ?
it’s not directly aws related, but i’m wondering if your problem is a software or infrastructure problem and for me, it sounds like you want to have specific workflows happening that trigger each other, etc.
and you can use conductor to call the lambdas etc.
if i’m misunderstanding and you want orchestration of your lambdas only, then StepFunctions like u/kayeyess mentioned can help, but managing 500 differneet jobs will still be not so easy >D
I would create a job for a single scheduler lambda, maybe have it fire messages each minute to worker lambdas to handle. Trigger the scheduler with eventbridge. Store your jobs in a table and have the scheduler read those from the table for each invocation. Check the clock against a sorted key of some field like scheduledTime. Then fire off messages to the appropriate queue where the worker can pick it up.
What is the annoying part? You have a discrete schedule for each job with a specific payload. There is no way around this complexity. You have to either store this within EventBridge Scheduler (IaC such as Terraform is recommended) or store this in a custom DB and build a management application around it.
It depends on where you prefer to deal with the complexity. If you prefer complexity in your codes, then use lambda as your orchestrator. But if you prefer to deal with complexity at declaration/configuration level, then Step Function is it.
Store each schedule separately in EB. Each schedule can hold its own payload that you pass to your Lambda. Put an SQS queue between two lambdas if you get lots of jobs so you have a bucket to drain.
Create a DDB table that holds cron expressions and job definitions. Run a lambda every minute and evaluate whether the cron expression is currently true. I’ve used python croniter for this.
I’m moving away from the second choice in favor of the first as my stuff scales up. I think when I first built some of my orchestration, I was using CW triggers as the cron part, and I was worried about hitting the quota on triggers available to me. Either I misunderstood something or recent enhancements to EB have allowed schedules in the billions. Moving to EB will allow each of my crons to function independently of each other and there will be no need to evaluate a bunch cron expressions to find the true ones, which could cause a delay in job start.
See I’m leaving on the first approach mostly because my jobs are not stetic and daily have a high rate of time modification, New jobs and removing jobs. The turnover in the call it cron like entries is about 60% a day across hundreds of jobs.
Doesn’t management itself of EB start to be a nightmare at that point? That’s sort of my fear is that some aws boto call fails and I have an orphaned job in a long list of EB defs and I have no easy way to identify it vs say some sql queries. I guess that’s my biggest concern.
That’s my initial view. Instead of thousands of discrete EB triggers just have a lambda run every min and do the orchestration. I was just wondering if that’s best practices.
Rebuilding it from scratch isn’t it.
What you need is better governance and management over the process, not a different service.
Of go full backwards and spin a vm
I am confused why you are not just having whatever code would update the database update the event bridge rule. Having 1440 lambda invocations a day, each having to read from a database and then determine if they should run, seems over complex when you could just trigger a lambda when a cron should change, or be created, or be removed and have it make the correct changes to EB.
It’s not that your minute cron trigger is “Bad” but I guess I don’t see what your real problem with EB is that you can not solve this by solving the discrete problem you have.