我使用 imangemin 和 imagemin-optipng nodejs 插件在 aws 上创建了一个 lambda 函数,但它返回以下错误:
错误:产生/var/task/node_modules/optipng-bin/vendor/optipng ENOENT
var aws = require('aws-sdk');
var s3 = new aws.S3()
var Imagemin = require('imagemin');
var optipng = require('imagemin-optipng');
exports.handler = function(event, context, callback){
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey =
decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
var params = {Bucket: srcBucket, Key: srcKey};
s3.getObject(params).promise()
.then(data => Imagemin.buffer(data.Body, {
plugins: [
optipng({ optimizationLevel: 7 })
]
})
)
.then(buffer =>
console.log('done ', buffer)
)
.catch(err => callback(err))
};