I have one sqs-fifo
receiving payment notifications from another service that insert items into this sqs-fifo
queue.
I also have one lambda that is configured to be triggered by the sqs-fifo
(lambda is not polling via code but configured in aws itself to be triggered by the sqs)
The messages are inserted into the sqs-fifo
with MessageGroupId=orderId
I still see that sometimes different lambdas handle different notifications in parallel for exactly same orderId.
Example of what I have now:
Time Payload
00:00 {orderId:1,status:pending} -> lambda request id 222aaa
00:01 {orderId:1,status:charged} -> lambda request id someuuid
Example of what I want to have, version 1 a)
Time Payload
00:00 {orderId:1,status:pending} -> lambda request id 222aaa
above call finishes at 00:02, than starts the second request
00:02 {orderId:1,status:charged} -> lambda request id someuuid
Example I want to have, version 2 - batch records for same orderId in same lambda a)
Time Payload
00:00 [{orderId:1,status:pending}, {orderId:1,status:charged}] -> lambda request id whatever
Is there any way to enforce that these messages are processed one by one via the aws lambda ?
It is very important to avoid race conditions regarding the order of processing payment events for the same orderId
To summarise what I want to achieve:
I want to handle notifications coming for same orderId X only by one particular lambda and avoid more than 1 lambda in parallel being executed for notifications regarding the order with id X. Meanwhile it is fine to spawn one lambda for notification for order X and another one for order Y. That will allow for scalability as I have lots of orders every minute.