Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aws Lambda response error

I am running aws lambda which will fetch data from maria DB and return the fetched rows as a JSON object. A total number of item in JSON array is 64K.

I am getting this error:

{ "error": "body size is too long" }

Is there a way I can send all 64K rows by making any configuration change to lambda?

like image 508
Irfan Pathan Avatar asked Sep 19 '17 10:09

Irfan Pathan


People also ask

How do you troubleshoot Lambda errors?

To troubleshoot Lambda code errors You can use CloudWatch to view all logs generated by your function's code and identify potential issues. For more information, see Accessing Amazon CloudWatch Logs for AWS Lambda.

What is Lambda error regex?

Our API Gateway's Lambda Error Regex runs a check when throwing an exception in Lambda Function. It does not run on a regular response. Our Lambda Function packs the exception into an object called errorMessage by herself.

How do you handle Lambda errors in API gateway?

Make sure that you also set up the corresponding error code ( 400 ) on the method response. Otherwise, API Gateway throws an invalid configuration error response at runtime. At runtime, API Gateway matches the Lambda error's errorMessage against the pattern of the regular expression on the selectionPattern property.


3 Answers

You cannot send the 64K rows (Which goes beyond 6MB body payload size limit) making configuration changes to Lambda. Few alternative options are.

  • Query the data and build a JSON file with all the rows in /tmp (Up to 512MB) directory inside Lambda, upload it to S3 and return a CloudFront Signed URL to access the data.
  • Split the dataset into multiple pages and do multiple queries.
  • Use a EC2 instance or ECS, instead of Lambda.

Note: Based on the purpose of queried data, its size & etc. different mechanisms can be used, efficiently using other AWS services.

like image 90
Ashan Avatar answered Oct 05 '22 08:10

Ashan


This error indicates that your response exceeds the maximum (6 MB), which is maximum data size AWS Lambda can respond.

http://docs.aws.amazon.com/lambda/latest/dg/limits.html

like image 41
Vijayanath Viswanathan Avatar answered Oct 05 '22 08:10

Vijayanath Viswanathan


It seems that you're hitting the hard limit of a maximum 6 MB response size. As it's a hard limit there's unfortunately no way to increase this.

You'll need to set up your lambda to be able to send at most 6MB and paginate through the rows you need to retrieve in different invocations until you've fetched all 64K.

Sources: https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list https://forums.aws.amazon.com/thread.jspa?threadID=230229

like image 34
gjtempleton Avatar answered Oct 05 '22 09:10

gjtempleton