Menu

Stop Duplicate Lambda Runs with a DynamoDB Lease and Fencing Token
πŸ“°

Stop Duplicate Lambda Runs with a DynamoDB Lease and Fencing Token

DEV Community: serverlessΒ·Sascha Mirow-StanitzokΒ·about 17 hours ago
#SvdN80Rc
#devtoserverless#devto#dev#nightly#lock
Long article (812 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Here is a situation I have seen more than once: a scheduled Lambda function creates invoices every night, and one morning a customer has two identical invoices. Nobody deployed anything unusual. The function simply ran twice, and both runs did their job perfectly.

That is not a bug in Lambda. Asynchronous invocations are retried on failure, the same event can arrive more than once even without an error, and sometimes a colleague starts a run manually because it "looks stuck". Each case is rare, but together they are more common than you would hope. In my article on building a DynamoDB lease lock for Lambda I walk through a complete, tested solution in TypeScript. This post explains the core ideas.

First ask whether you need a lock at all

A distributed lock is extra coordination you have to test, monitor and explain.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.