Answers: <p>Use SQS with Lambda to accomplish this.</p>
  <p>SQS supports 2 types of queues: Standard &amp; FIFO. FIFO is appropriate for your use case. Create a FIFO queue &amp; attach a Lambda function trigger to it. This causes the Lambda function to be triggered when a message arrives in the SQS queue. When you send a message to a FIFO queue, set the <code>userId</code> as the <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html" rel="nofollow noreferrer">message group ID</a>. This will ensure that messages from an individual user are only processed serially but messages from different users are processed in parallel.</p>
  <p>Here's the relevant section from <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-scaling" rel="nofollow noreferrer">AWS Lambda documentation</a>:</p>
  <blockquote>
  <p>For FIFO queues, Lambda sends messages to your function in the order that it receives them. When you send a message to a FIFO queue, you specify a message group ID. Amazon SQS ensures that messages in the same group are delivered to Lambda in order. Lambda sorts the messages into groups and sends only one batch at a time for a group. If the function returns an error, all retries are attempted on the affected messages before Lambda receives additional messages from the same group. Your function can scale in concurrency to the number of active message groups.</p>
  </blockquote>
  
Answers: CC BY-SA 4.0
Answers: 2020-07-19T01:06:25.377Z
Answers: Exactly what I was looking for, thanks a lot.
Answers: Joe
Answers: CC BY-SA 4.0
Answers: 2020-07-17T18:24:40.633Z
Answers: 2020-07-17T18:24:40.633Z
Answers: Harish KM
Body: <p>I'm not sure if this is the best place to ask this. But we've currently got something in Microsoft Azure where we have their serverless functions (Azure Functions) running in serial based off a particular key, say a user ID.</p>
  <p>So I want these functions to be called in parallel for different users, but in serial for each individual user. I spent ages trying to do this with locking behaviour in the function logic but it was always causing issues until I discovered with Azure, I simply make my Azure Function trigger from Service Bus, and use the <code>userId</code> as the <a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-sessions" rel="nofollow noreferrer">Service Bus session id</a>. Then Azure makes sure only one 'session' is running at once.</p>
  <p>We're looking at moving stuff over to AWS and Lambda functions, but there's so many services - AWS Firehose, Simple Queue, CloudWatch Events, Step Functions, Kinesis Data Stream. In my initial searching I couldn't find any references to something similar (but everything is called different things, and I can spend hours reading about a service and find it's totally nothing to do with what I'm trying to accomplish)</p>
  <p>Does anyone know if any of them offer that kind of &quot;serial for a given property&quot; kind of behaviour out of the box?</p>
  
Tags: <amazon-web-services>
Title: Running AWS lambda in serial (for a given parameter)
UserDisplayName: Joe
ThreadText: # Running AWS lambda in serial (for a given parameter)
  
  (Asked by: username_0 on 2020-07-17)
  
  I'm not sure if this is the best place to ask this. But we've currently got something in Microsoft Azure where we have their serverless functions (Azure Functions) running in serial based off a particular key, say a user ID.
  
  So I want these functions to be called in parallel for different users, but in serial for each individual user. I spent ages trying to do this with locking behaviour in the function logic but it was always causing issues until I discovered with Azure, I simply make my Azure Function trigger from Service Bus, and use the `userId` as the [Service Bus session id](https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-sessions). Then Azure makes sure only one 'session' is running at once.
  
  We're looking at moving stuff over to AWS and Lambda functions, but there's so many services - AWS Firehose, Simple Queue, CloudWatch Events, Step Functions, Kinesis Data Stream. In my initial searching I couldn't find any references to something similar (but everything is called different things, and I can spend hours reading about a service and find it's totally nothing to do with what I'm trying to accomplish)
  
  Does anyone know if any of them offer that kind of "serial for a given property" kind of behaviour out of the box?
  
  **Tags:** amazon-web-services
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-17. Score: 2 | Accepted answer
  
  Use SQS with Lambda to accomplish this.
  
  SQS supports 2 types of queues: Standard & FIFO. FIFO is appropriate for your use case. Create a FIFO queue & attach a Lambda function trigger to it. This causes the Lambda function to be triggered when a message arrives in the SQS queue. When you send a message to a FIFO queue, set the `userId` as the [message group ID](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html). This will ensure that messages from an individual user are only processed serially but messages from different users are processed in parallel.
  
  Here's the relevant section from [AWS Lambda documentation](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-scaling):
  
  > For FIFO queues, Lambda sends messages to your function in the order that it receives them. When you send a message to a FIFO queue, you specify a message group ID. Amazon SQS ensures that messages in the same group are delivered to Lambda in order. Lambda sorts the messages into groups and sends only one batch at a time for a group. If the function returns an error, all retries are attempted on the affected messages before Lambda receives additional messages from the same group. Your function can scale in concurrency to the number of active message groups.
  
  > **Comments:**
  > **username_0**: Exactly what I was looking for, thanks a lot.  
  
  ---
  
  