I am using a lambda function to service a REST API. In one endpoint I am getting "body size is too long" printed to the cloudwatch log.
The response I get from the function is status code 502 with response body { "message": "Internal server error" }. If I call the same endpoint but use a filter, the response body size is 2.26MB and works. This rules out that I am hitting asynchronous response body limit.
The response body size when it errors out is 5622338 bytes (5.36 MB).
This is how I am calculating the response size (python 2.7):
import urllib2
...
out = {}
resp = urllib2.urlopen(req)
out.statusCode = resp.getcode()
out.body = resp.read()
print("num bytes: " + str(len(bytearray(out.body, 'utf-8'))))
The advertised max response body size is for synchronous invocations is 6MB. From what I understand, I should not be receiving the error. https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html
Other information:
Duration: 22809.11 ms Billed Duration: 22810 ms Memory Size: 138 MB Max Memory Used: 129 MB Init Duration: 1322.71 ms
Any help would be appreciated.
Update 4/22/21
After further research I found that the lambda function errors out if the size of the response is 1,048,574 bytes (0.999998 MB) or more.
If the response is 1,048,573 bytes (0.999997 MB) or less it works.
This is how I am returning responses. I hard code the view function to return a bytearray of a specific size. Ex.
return bytearray(1048573)
I turned on logging for the AWS Gateway Stage that I am using, and the following error is getting written to the log. It implies that the function is erroring out. Not the invocation of the function: Lambda execution failed with status 200 due to customer function error: body size is too long.
It's my understanding that the AWS Lambda Functions have a max response size of 6MB and the AWS Gateways have a max response size of 10MB.
AWS Lambda: Invocation payload response https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html
API Gateway: API Gateway quotas for configuring and running REST API -> Payload size https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
Am I misunderstanding the limits?