AWS Lambda and SQS Payload Limitation

In this post, we’re talking about deploying an AI service that processes the political news articles in Almeta’s database.

The service is assumed to be deployed as AWS Lambda function, with the use of AWS SQS to maintain the incoming requests while the function is throttled.

An important limit to be considered in such a situation, is the limit that is put on the payload size by both AWS Lambda and AWS SQS. Along this post, we investigate what is this limit for each of the two services and how are we affected by it.

AWS SQS

There are two types of SQS:

  • Standard Queues
  • FIFO Queues

According to the use cases provided by AWS the standard one fits our case. Refer to https://aws.amazon.com/sqs/features/ for the comparison and use cases.
In this post, we’re talking about the Standard Queues.

AWS SQS Payload Size Limitation

Message payloads can contain up to 256KB of text in any format.
Each 64KB ‘chunk’ of the payload is billed as 1 request.

For example, a single API call with a 256KB payload will be billed as four requests.

To send messages larger than 256KB, you can use Amazon S3 to store the message payload. Then a reference to the message payload is sent using SQS.

What Do We Have?

In this section, we’re investigating if we’re limited with the SQS payload size limit.

The following analysis was done on our Almeta’s database snapshot for September and October 2019, and only for articles tagged as political news.

Assuming that our message would contain:

  1. articleId
  2. title
  3. content
  4. publishDate

For each news article in the snapshot, we generated a JSON record contains these values and encoded it with json.dumps in Python. Then the generated JSON string size was calculated in KB.

Following is a histogram shows the supposed message size distribution over all the news articles:

Conclusions:

  • Fortunately, seems we won’t exceed the payload size limit, as most of the payload sizes are below 40 KB.
  • We can confidently skip processing any page that exceeds this limit as they are definitely too rare as we can see.

Other Limitations

Contents of requests:

A single request can have from 1 to 10 messages, up to a maximum total payload of 256 KB.

Thus, if we are arranging to send a batch of messages:

  1. First, we wouldn’t be able to send batches bigger than 10 messages. Which is a limitation for SQS.
  2. Second, we should make sure that the size of the whole payload in our batch doesn’t exceed the payload limit 256 KB.

Requests free tier limitation:

AWS SQS provides the following free tier:
The first 1 million monthly requests are free. After that, the pricing is as follows for Al-Bahrain region: 

Pricing per Request after the free tier is: $0.0000004 per request

Following are two graphs show the average fetched news articles count, per day per month (September & October):

On average we are fetching ~ 159 +/- 50 news articles per day => Maximum ~ 6270 Articles per month.

As we have free 1 million SQS requests per month, we won’t pay for this according to our analysis.

AWS Lambda Function

Regarding the Lambda function:

Its invocation payload (for both request and response) is:

  • 6 MB (synchronous)
  • 256 KB (asynchronous)

According to our previous discussion, that is most of our payload sizes are below 40 KB, we’re safe for both of the options.

Do you know that we use all this and other AI technologies in our app? Look at what you’re reading now applied in action. Try our Almeta News app. You can download it from Google Play or Apple’s App Store.

2 thoughts on “AWS Lambda and SQS Payload Limitation

Leave a Reply

Your email address will not be published. Required fields are marked *