Reputation: 771
I have a list of Lambda worker functions (say 1000), each running simultaneously and doing its job. To be able to figure out the end result of all workers I have come up with this idea.
Before starting the job and spawning the Lambda worker functions, I save a record in DynamoDB, for example two attributes:
total_number_of_jobs
jobs_completed
(set initially to 0)On finish of each Lambda worker function it will go and increment the attribute jobs_completed
by one. Then read the record and check if total_number_of_jobs
equals to jobs_completed
and if it is, put a record in SQS.
My questions are:
I would update the counter, jobs_completed
, in an UpdateItem API call like this:
SET jobs_completed = jobs_completed + :incr_by
where incr_by
would be equal to 1
.
Upvotes: 4
Views: 7010
Reputation: 200436
As long as you use DynamoDB atomic counters, like your example shows, and you check the return value of the UpdateItem call instead of running a separate query, then your proposed solution should work fine.
Upvotes: 5