Jeff Pal
Jeff Pal

Reputation: 1674

CORS issue with AWS lambda when the payload is too large

I have a lambda function, deployed with Serverless Framework, that's giving the error below, only when the Payload is too large. I'm sending a file through a POST multipart/form-data and the CORS is enabled on ApiGateway. But it seems, in case Payload is too large, the lambda doesn't event reach my code, if so AWS returns a response without headers.

Console

Access to XMLHttpRequest at 'https://my-lambda-endpoint' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Network

enter image description here

If I enable CORS extension on my browser, then I get a different error:

Error: Request failed with status code 413
HTTP content length exceeded 10485760 bytes.

Upvotes: 0

Views: 1010

Answers (2)

bds
bds

Reputation: 188

Go to Gateway responses for the API Gateway. Edit Default RXX and set Access-Control-Allow-Origin to a specific value or '*'. Save and then deploy the API.

Upvotes: 0

Dunedan
Dunedan

Reputation: 8435

The maximum request payload size for API Gateway is 10MB. If the payload is larger than that API Gateway directly returns the error message you're seeing, without invoking the integration (AWS Lambda in your case).

You can find more information about this and other quotas in the documentation:

https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html

Upvotes: 1

Related Questions