AWS Lambda响应错误

问题描述:

我正在运行aws lambda,它将从maria DB中获取数据,并将获取的行作为JSON对象返回. JSON数组中的项目总数为64K.

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.

我收到此错误:

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

是否可以通过对lambda进行任何配置来发送所有64K行?

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

您无法发送64K行(超出6MB正文有效负载大小

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

  • 查询数据并使用Lambda内的/tmp(最大512MB)目录中的所有行构建一个JSON文件,将其上传到S3并返回
  • 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.

注意:根据查询数据的目的,其大小等.可以使用不同的机制来有效地使用其他AWS服务.

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