I have a scenario where I have a DynamoDB table with a trigger (a stream) to an AWS Lambda function.
I want to use DynamoDB as an Event Store and use the Lambda function to maintain a projection / aggregate view / read view of the data.
I need to make sure that when I save an CreateEntity event in DynamoDB and then maybe right after when I save an UpdateEntity that the Lambda function will process the CreateEntity event before the UpdateEntity event.
My understanding is that the parallelism of the triggers to Lambda depends on the number of Shards the DynamoDB stream consists of. So if the DynamoDB Stream that the Lambda function use have 2 shards and one event goes on Shard1 and the other event goes on Shard2 then they can be processed in parallel by two instances of the Lambda function.
So if the CreateEntity event is on Shard1 and UpdateEntity is on Shard2 then if Shard1 or the Lambda function instance for some reason is slow then the UpdateEntity event in Shard2 might be processed first. Meaning that it cannot be added to the projection because there is no entity created first.
Is my understanding correct?
Is there a way to ensure that the events are only processed by one instance of the Lambda function so that I can ensure the ordering of processing of the messages?
Or do I have to use something else than Lambda for this? For example DynamoDB stream to Kinesis with my own application where I can ensure that only one instance of the application is running and ensure the ordering this way.