Lambda response compression to API Gateway and client

1

We have a REST API in API Gateway that uses Lambda functions. Sometimes the amount of data we want to send back exceeds the Lambda limit of 6+ MB. I know there's an easy way to tell API Gateway to compress responses if the request asks for it, and the library we are using to make the requests works great with that. The problem is that it doesn't help since the Lambda itself is sending 6+ MB back to the API Gateway and that is where the failure occurs. Is there a different built-in way to have the Lambda's output compressed and sent to the API Gateway and then have the API Gateway handle it like it does now in the sense that the same information is sent back as the response so the client library handles it in the standard way?

已提問 2 年前檢視次數 1171 次
2 個答案
0

If your Lambda function is already compressing the result then you need to use a different way to return the larger payload to the client that doesn't involve API Gateway.

The most commonly used way of doing this is to have the Lambda function upload the object to S3; then generate a pre-signed URL and return that to the client. After a specific period of time, delete the object in S3 (you might also do this with lifecycle policies).

profile pictureAWS
專家
已回答 2 年前
  • Sorry if I wasn't clear on what is happening now vs what I would like to happen. Right now there is no compression going on in the Lambda. If I turn on the API Gateway compression option, everything works fine in the sense that the client sends the right headers and the API Gateway respects those headers and does whatever it needs to do. But that built-in functionality still accepts the current uncompressed output from the Lambda function, which still has the 6+MB limit. What I was hoping for is the "manual" approach to doing what API Gateway does when you enable the built-in setting. i.e., I'll compress in my Lambda, but then I need to know what to do to the API Gateway so that the compressed data it is receiving from the Lambda gets passed on through to the requesting client with the same kinds of headers etc. so that it knows to decompress it.

0

See: https://mxro.medium.com/compression-for-aws-http-api-gateway-a86ad8d39ada A similar set of steps may be followed for the REST API. Note: Make sure you check the accept-encoding header that was sent with the request before sending the response.

profile picture
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南