Create a zip file on S3 from files on S3 using Lambda Node

前端 未结 3 999
不思量自难忘°
不思量自难忘° 2020-12-05 10:29

I need to create a Zip file that consists of a selection of files (videos and images) located in my s3 bucket.

The problem at the moment using my code below is that

3条回答
  •  鱼传尺愫
    2020-12-05 10:48

    Using streams may be tricky as I'm not sure how you could pipe multiple streams into an object. I've done this several times using standard file object. It's a multistep process and it's quite fast. Remember that Lambda operates in Linux so you have all Linux resources at hand including the system /tmp directory.

    1. Create a sub-directory in /tmp call "transient" or whatever works for you
    2. Use s3.getObject() and write file objects to /tmp/transient
    3. Use the GLOB package to generate an array[] of paths from /tmp/transient
    4. Loop the array and zip.addLocalFile(array[i]);
    5. zip.writeZip('tmp/files.zip');

提交回复
热议问题