skip to Main Content

I lambda function that returns a bunch of requests that I want to send to an external service. This external service has an api with the following rate limit:

Paramters: 
type: enum
content: list of n elements

Rate limit: 
For each type, there can be no more than 3 concurrent slots. Each slot will be will need to wait n milliseconds between requests. 

I want to throttle the requests being sent. My deign is to use sqs to queue the request payloads and set an autoscaling lambda to consume them. The sqs configuration includes a max_concurrency, but I dont see a way to configure that based on the message content.

Is there a way to implement the rate limit throttling described above using SQS? Or should I use another solution like Amazon MSK?

Example:

For below queue, I want a lambda function to be able to concurrently process 3 messages for type 1, 3 messages for type 2, and so on.

queue: 
type=1, payload
type=1, payload
type=1, payload
type=1, payload
type=2, payload
type=2, payload
type=2, payload
type=3, payload

2

Answers


  1. You would need to:

    • Configure the AWS Lambda function to have Reserved Concurrency = 3
    • Add a sleep command to the end of your Lambda function to wait the required time

    The Reserved Concurrency – AWS Lambda will ensure that a maximum of 3 functions can run at the same time.

    The sleep will delay the start of the next function. Unfortunately, it means that the Lambda function will be running for a longer time and you will be paying for the Lambda function to effectively do nothing.

    Login or Signup to reply.
  2. If you want to process messages differently, you would need to:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search