如何绕过AWS API网关的10MB限制并将大文件POST到AWS lambda? [英] How can I bypass the 10MB limit of AWS API gateway and POST large files to AWS lambda?

查看:454
本文介绍了如何绕过AWS API网关的10MB限制并将大文件POST到AWS lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用POST接收文件和一些参数并返回JSON响应的API.

An API which takes file and some parameters using POST and gives back a JSON response.

curl -X POST www.endpoint.com \
   -F file=@/myfile.txt \
   -F foo=bar # other params

我可以使用二进制数据使用Lambda + API网关,但问题是10MB.

I have this working with Lambda + API gateway using binary data but 10MB limit is the issue.

我考虑过将文件上传到S3的POST API.然后,Lambda读取生成的事件.但是为此,我有几个问题-

I have considered a POST API which uploads file to S3. The event generated is then read by Lambda. But for this I have few questions-

  1. 我的其他参数会去哪儿?
  2. Lambda将如何返回响应?

推荐答案

如果您要坚持使用无服务器解决方案,那么仅用一个API调用就无法实现您的用例.

Your use case simply isn't possible with one API call if you want to stick with a serverless solution.

对于客户端来说,可能的无服务器解决方案将是一个三步过程.

A possible serverless solution would be a 3 step process for the client.

第1步

调用api1获取S3的签名URL.这将指向一个Lambda,该Lambda创建一个UUID并使用该UUID为S3构造一个签名的URL(即,使用UUID作为接收文件的文件名).响应将是URL和UUID.

Call api1 to get a signed url for S3. This would point to a Lambda that creates a UUID and uses that UUID to construct a signed URL for S3 (i.e. uses the UUID as the filename of the file being received). The response would be the URL and the UUID.

第2步

使用签名的URL将文件放入s3.

PUT file to s3 using the signed URL.

第3步

调用api2并传递UUID以及所有其他需要的参数.该api还指向Lambda,该Lambda现在知道文件在哪里(由于UUID),并且具有处理文件并给出响应所需的其他任何参数.

Call api2 and pass the UUID and what ever other parameters are required. This api also points to a Lambda which now knows where the file is (thanks to the UUID) and has whatever other parameters are required to process the file and give a response.

这篇关于如何绕过AWS API网关的10MB限制并将大文件POST到AWS lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆