Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronization between aws lambdas

I am using several AWS lambda functions (and multiple instances of the same ones) to access objects within AWS. Any information on thread safety of lambdas? While order of writing is not important (in my case), atomicity of read-modify-write is. Anyone came across proper/intended solution?

like image 784
VitalyR Avatar asked Mar 23 '26 15:03

VitalyR


1 Answers

I came across this because I'm trying to achieve the same thing.

Problem: I have a cluster of state machines running in EC2 instances. Each invokes a Lambda asynchronously (InvocationType.Event). I want to run the lambda code each time but perform a downstream network call only once from within the lambda.

Solution: Using a DynamoDB table with a relatively low TTL, I perform a conditional put of an item with unique id generated from event data that will be the same across all lambda invocations for that unique event. Then, I only perform the downstream network call if the conditional put succeeds.

It's a distributed synchronization technique often used in distributed systems for "fail-fast" systems, just via a lambda.

like image 84
jeffery Avatar answered Mar 26 '26 09:03

jeffery