Download image from S3 bucket to Lambda temp folder (Node.js)

后端 未结 3 812
后悔当初
后悔当初 2020-12-31 15:55

Good day guys.

I have a simple question: How do I download an image from a S3 bucket to Lambda function temp folder for processing? Basically, I nee

3条回答
  •  长发绾君心
    2020-12-31 16:59

    If you're writing it straight to the filesystem you can also do it with streams. It may be a little faster/more memory friendly, especially in a memory-constrained environment like Lambda.

    var fs = require('fs');
    var path = require('path');
    
    var params = {
        Bucket: "mybucket",
        Key: "image.png"
    };
    
    var tempFileName = path.join('/tmp', 'downloadedimage.png');
    var tempFile = fs.createWriteStream(tempFileName);
    
    s3.getObject(params).createReadStream().pipe(tempFile);
    

提交回复
热议问题