3

I am currently using AWS API Gateway in combination with a lambda invocation. This is working perfectly, as long as I stay withing the known AWS Lambda Limits. One of the calls receives a file via a POST request, so that goes fine as long as the file is < 6 MB.

However when the file is too large, I get a 502 Bad Gateway response. This is not really helpful to the client, I would rather return a 413 Payload Too Large. How can I do this? I haven't found a way so far, looking at the API Gateway options.

Bram Vandewalle
  • 1,624
  • 3
  • 20
  • 29
  • More than that, API Gateway has limits too: https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html - Payload size Max 10Mb – Ele Jan 16 '18 at 16:14
  • I think, you need to validate the file's size before sending any request to the API Gateway endpoint. My approach to avoid this kind of problems is working with API Gateway + Lambda + s3. – Ele Jan 16 '18 at 16:18
  • Accoding to the doc, API Gateway is already supposed to return a 413 : https://docs.aws.amazon.com/apigateway/latest/developerguide/supported-gateway-response-types.html it should work with a file > 10 MB :) – Gabriel Bleu Jan 16 '18 at 16:21
  • 3
    Note that the [Lambda limit](https://docs.aws.amazon.com/lambda/latest/dg/limits.html) for synchronous Invoke request payload is only 6MB. There seems to be an edge case that one might expect to occur between 6 and 10MB. Lambda should be throwing back a 413 to API Gateway, but API Gateway might be translating that to a 502 [because Lambda isn't returning the expected response](https://forums.aws.amazon.com/thread.jspa?messageID=760018) format. (Speculation.) – Michael - sqlbot Jan 16 '18 at 23:07
  • Seems like you are correct Michael, the logs do mention an incorrect response format. I am unsure how to get this fixed thoug, since it is generated by AWS. – Bram Vandewalle Jan 17 '18 at 15:35
  • anyone ever figure this out? – jdixon04 Jun 21 '18 at 23:36
  • 1
    We've chosen to create a signed S3 URL for our application to upload the file, rather than POSTing it via API Gateway + Lambda. There is no way to change the 10MB API Gateway or 6MB Lambda limit. – Bram Vandewalle Jun 25 '18 at 09:35

0 Answers0