错误:使用AWS Lambda上的gm降低图片质量时,stream会产生空缓冲区

我已阅读所有其他主题,并尝试了一些答案,但我似乎无法弄清楚为什么我得到这个错误。 我的代码在S3存储桶中获取上传的图片,降低质量并将其放入第二个存储桶中。 干净利落。 随着中小型图像一切正常,但如果我上传的东西超过2 MB(或多或less)我得到的错误标题。 我的Lambda函数有128MB和3分钟的超时时间; 这里是代码:

const gm = require('gm').subClass({imageMagick: true}); const AWS = require('aws-sdk'); const async = require('async'); const S3 = new AWS.S3(); exports.handler = (event, context, callback) => { var srcBucket = event.Records[0].s3.bucket.name; var srcKey = event.Records[0].s3.object.key; var dstBucket = "destinationbucket"; var dstKey = "resized-" + srcKey; // Infer the image type. var typeMatch = srcKey.match(/\.([^.]*)$/); if (!typeMatch) { callback("Could not determine the image type."); return; } var imageType = typeMatch[1].toLowerCase(); if (imageType != "jpg" && imageType != "png" && imageType != "jpeg") { callback('Unsupported image type: ${imageType}'); return; } async.waterfall([ function download(next) { S3.getObject({Bucket : srcBucket, Key : srcKey}, next); }, function transform(response, next) { var img_quality_reduced = gm(response.Body); img_quality_reduced.quality(75).toBuffer(function( error, buffer ) { if( error ) { console.log( error ); return; } next(null, response.ContentType, buffer); } ); }, function upload(contentType, data, next) { S3.putObject({Bucket: dstBucket, Key: dstKey, Body: data}, next); }, function ending(next) { console.log('got to ending'); context.done(); } ], function (err) { console.log(err); context.done(); }); }; 

任何想法为什么发生这种情况? 我已经加载了async,gm和graphicsmagick到Lambda(作为一个zip文件)。 所有通过npm下载