简体   繁体   English

使用 API 网关将大型文件上传/下载到 Lambda function 而不使用任何 S3 存储桶

[英]Upload/Download LARGE files to/from Lambda function using API Gateway without making any use of S3 Bucket

I'm implementing a serverless API , using:我正在实施无服务器API ,使用:

  1. API Gateway API 网关
  2. Lambda Lambda
  3. S3 Bucket "If needed" S3 存储桶“如果需要”

My flow is to:我的流程是:

  1. Call POST or PUT method with a binary file "zip", upload it to Lambda.使用二进制文件“zip”调用 POST 或 PUT 方法,将其上传到 Lambda。
  2. In Lambda: unzip the file.在 Lambda 中:解压缩文件。
  3. In Lambda: Run a determined script over the extracted files.在 Lambda 中:在提取的文件上运行确定的脚本。
  4. In Lambda: Generate a new zip.在 Lambda 中:生成新的 zip。
  5. Return it to my desktop.把它放回我的桌面。

This flow is already implemented and it's working well with small files, 10MB for uploading and 6MB for downloading.这个流程已经实现,它适用于小文件,10MB 用于上传,6MB 用于下载。 But I'm getting issues when dealing with large files as it'll be the case on many occasions.但是在处理大文件时我遇到了问题,因为在很多情况下都会出现这种情况。 To solve such issue I'm thinking about the following flow:为了解决这样的问题,我正在考虑以下流程:

  1. Target file gets uploaded S3 Bucket.目标文件被上传 S3 存储桶。
  2. A new event is generated and Lambda gets triggered.生成一个新事件并触发 Lambda。
  3. Lambda Internal Tasks: Lambda 内部任务:

    3.1 Lambda Download the file from S3 bucket. 3.1 Lambda 从 S3 存储桶下载文件。

    3.2 Lambda Generate the corresponding WPK Package. 3.2 Lambda 生成对应的WPK Package。

    3.3 Lambda Upload the generated WPK package into S3. 3.3 Lambda 将生成的 WPK package 上传到 S3。

    3.4 Lambda returns a signed URL related to the uploaded file as a response. 3.4 Lambda 返回与上传文件相关的签名 URL 作为响应。

But my problem with such design is that it requires more than a request to get completed.但我对这种设计的问题是它需要的不仅仅是完成一个请求。 I want to do all this process in only 1 request, passing the target zip file in it and get the new zip as the response.我只想在 1 个请求中完成所有这些过程,在其中传递目标 zip 文件并获取新的 zip 作为响应。 Any Ideas, please?请问有什么想法吗?

My Components and Flow Diagram would be:我的组件和流程图将是:

Component and Flow Diagram组件和流程图

There are a couple of things you could do if you'd like to unzip large files while keeping a serverless approach:如果您想在保持无服务器方法的同时解压缩大文件,您可以做几件事:

  1. Use Node.js for streaming of the zip file, unzipping the file in a pipe, putting the content in a write stream pipe back to S3. Use Node.js for streaming of the zip file, unzipping the file in a pipe, putting the content in a write stream pipe back to S3.
  2. Deploy your code to an AWS Glue Job.将您的代码部署到 AWS Glue 作业。
  3. Upload the file to S3,AWS Lambda gets triggered pass the file name as the key to the glue job and the rest will be done.将文件上传到 S3,AWS Lambda 被触发,将文件名作为粘合作业的密钥,rest 将完成。 This way you have a serverless approach and a code that does not cause memory issues while unzipping large files这样,您就有了一种无服务器方法和一个在解压缩大文件时不会导致memory问题的代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 lambda 从外部 s3 存储桶下载文件 - Download files from external s3 bucket using lambda 是否可以通过AWS API Gateway和lambda函数将PDF文件上传到S3存储桶? - Is it possible to upload a PDF file through AWS API Gateway and a lambda function to a S3 bucket? 使用 API 网关从 S3 下载已压缩的文件 - Using API Gateway to download already gzipped files from S3 我可以使用 https 从私有 S3 存储桶下载对象而不公开存储桶或对象吗? - Can I download an object from private S3 bucket using https without making bucket or object public? 使用 HTML POST -> API-> Lambda -> s3 - 亚马逊 API 网关 p26 上传文件 - Upload files using HTML POST -> API-> Lambda -> s3 - Amazon API Gateway p26 如何使用nodejs使用无服务器框架使用lambda函数将图像/文件上传到s3存储桶? - How to upload images/files to s3 bucket using lambda function using serverless framework using nodejs? 如何使用 Lambda 函数将下载的文件上传到 s3 存储桶 - How to upload downloaded file to s3 bucket using Lambda function 使用 Lambda 和 API 网关上传到 S3 后文件损坏 - File corrupted after upload to S3 using Lambda and API Gateway 如何从S3存储桶读取大型XML文件,然后使用AWS Lambda将其用作HTTP请求正文 - How to read a large XML file from S3 bucket and then use it as an HTTP request body using AWS Lambda 从S3存储桶上传/下载数据 - Upload/download data from S3 bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM