I have a Lambda function that performs QLDB transactions. Because QLDB uses OCC (optimistic concurrency control), it’s necessary to add a SQS Fifo in front, making sure that potential conflicting transactions (in my case: transactions attached to a specific user) are processed in sequence.
Using the SQS SendMessage.waitForTaskToken
can solve this problem, but it requires the use of multiple workflows.
Is it possible to add to a SQS and wait for the just-added message to be emitted from the SQS? I’m trying to avoid splitting this step function up.
2
Answers
Based on my knowledge, instead of splitting the step function, you can create a solution that sends messages to the SQS FIFO queue and processes them sequentially using a Lambda function. The Lambda function can ensure that transactions attached to a specific user are processed one at a time.
Let’s see some ways you can go about this:
Lambda Function: This function is for processing
QLDB
transactions. Before executing the transaction, it publishes a message to theSQS FIFO
queue, making sure the message group ID is the ID of that user.SQS FIFO Queue: This queue ensures that messages from the same user will be processed in order. When a message is sent to the queue, it should wait until the message is processed before sending the next.
Seperate Lambda Function (Optional): You can have a separate lambda function for listening to messages from the
SQS
queue and do the processing. But since you want to avoid splitting your Step Function, you can directly have theSQS
queue integrated with the Step Function.Step Function: The Step Function arranges the entire thing. It starts by using the Lambda function responsible for
QLDB
transactions. Then it waits for a message to be emitted from theSQS FIFO
queue before doing the next step.