- 新しい順
- 投票が多い順
- コメントが多い順
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. Am I misunderstanding the limits?
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
I created a new lambda function for python 3.7 and found that it returns a more descriptive error. I was able to determine that the lambda function adds around 1 MB to the size of the response after it leaves the lambda function which explains why it was erroring out in the lambda function, but not in the endpoint code. In one case it added .82MB and another it add .98MB. It seems to be based off the size of the response. I suspect the response is getting base64 encoded, URL encoded, or something similar. I did not find documentation that could answer this and the responses were not encoded in any way on the receiving end.
**Error Message returned by lambda function build with python 3.7: **
Response payload size (8198440 bytes) exceeded maximum allowed payload size (6291556 bytes).
Lambda Function Code:
import requests, base64, json
def lambda_handler(event, context):
headers = {...}
url = ...
response = requests.get(url, headers=headers)
print (len(response.content))
print (len(response.content.decode("utf-8")))
return response.content.decode('UTF-8')
Below I have the size of the responses when printed inside the lambda function and the size of the response as determined by lambda in the error message.
I used these two print statements to determine the size of the response and these two print statements would always return the same length. Response.content is a byte array so my thought process is that getting the length of it will return the number of bytes in the response:
print (len(response.content))
print (len(response.content.decode("utf-8")))
Ex 1.
Size when printed inside the lambda function:
7,165,488 (6.8335 MB)
Size as defined in the error message:
8,198,440 (7.8186 MB)
Extra:
1,032,952 (0.9851 MB)
Error Message:
Response payload size (8198440 bytes) exceeded maximum allowed payload size (6291556 bytes).
Ex 2.
Size when printed inside the lambda function:
5,622,338 (5.3619 MB)
Size as defined in the error message:
6,482,232 (6.1819 MB)
Extra:
859,894 (0.820059 MB)
Response payload size (6482232 bytes) exceeded maximum allowed payload size (6291556 bytes).
I have decided to lower the soft limit in the endpoint code by another 1 MB to prevent hitting the limit in the lambda function.
関連するコンテンツ
- AWS公式更新しました 2年前
- AWS公式更新しました 2年前