简体   繁体   English

如何使用 lambda python 创建 zip 文件并上传回 s3?

[英]How to create zip file and upload back to s3 using lambda python?

Hope everybody is safe and happy.希望每个人都平安快乐。

I have given a AWS task as follow.我给了一个 AWS 任务如下。

Requirement: As soon as file gets uploaded in s3 bucket,it should be zipped and must be uploaded back to another s3 bucket.要求:一旦文件被上传到 s3 存储桶中,它应该被压缩并且必须上传回另一个 s3 存储桶。

I am able to complete this task using lambda(python) but it involves lots of disk IO.我能够使用 lambda(python) 完成此任务,但它涉及大量磁盘 IO。 So ,i am looking for a solution where i will not require to store incoming s3 object at /tmp/ folder.所以,我正在寻找一种解决方案,我不需要在 /tmp/ 文件夹中存储传入的 s3 对象。 As we all know , lambda provides very less memory and storage(500MB).众所周知,lambda 提供的内存和存储空间非常少(500MB)。 Hence, wants to avoid this approach.因此,想要避免这种方法。

So, does anybody aware of how to zip the incoming s3 file on the fly?那么,有人知道如何即时压缩传入的 s3 文件吗? I am only aware that, it possible to do with the help of streaming of s3 object.我只知道,可以在 s3 对象流的帮助下做到这一点。 But not able to find how it can be achieved end to end using python language.但无法找到如何使用 python 语言实现端到端。

Thanks in advance.提前致谢。

您可以在 Lambda 中使用 python 生成器来压缩 s3 文件并将 zip 文件放回另一个 s3 中,因为生成器不占用内存。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM