目标是每天使用AWS Lambda从URL复制特定的jpg文件到S3 Bucket中。这似乎是一个超级简单的Lambda函数,但它却无法正常工作。我已经在本地NPM项目中设置了这个功能,然后上传了压缩文件到AWS Lambda控制台。下面的代码运行没有错误,但是没有复制图片。非常感谢您能提供任何帮助。
"use strict";
const AWS = require("aws-sdk");
const Jimp = require("jimp");
const s3 = new AWS.S3();
const imageType = "image/jpeg";
const bucket = 'mybucket';
exports.handler = (event, context, callback) => {
let objectKey = 'myimage.jpg';
Jimp.read('sampleURL.com/image.jpg')
.then(image => {
s3.putObject({
Bucket: bucket,
Key: objectKey,
Body: image,
ContentType: imageType
})
})
.catch(err => {
// Handle an exception.
});
};
AWS CloudWatch 日志
2019-10-24T12:48:23.105Z bac7d80e-5544-4ea5-ae12-478281338389 INFO { Error: Could not find MIME for Buffer <null>
at Jimp.parseBitmap (/var/task/node_modules/@jimp/core/dist/utils/image-bitmap.js:120:15)
at Jimp.parseBitmap (/var/task/node_modules/@jimp/core/dist/index.js:506:32)
at /var/task/node_modules/@jimp/core/dist/index.js:448:15
at /var/task/node_modules/@jimp/core/dist/index.js:176:14
at /var/task/node_modules/@jimp/core/dist/request.js:66:9
at IncomingMessage.<anonymous> (/var/task/node_modules/phin/lib/phin.compiled.js:1:2100)
at IncomingMessage.emit (events.js:203:15)
at IncomingMessage.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19) methodName: 'constructor' }
END RequestId: bac7d80e-5544-4ea5-ae12-478281338389
REPORT RequestId: bac7d80e-5544-4ea5-ae12-478281338389 Duration: 612.63 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 97 MB Init Duration: 557.69 ms
// 处理异常
的地方有什么吗?如果没有任何内容,那可能是真正的异常被隐藏了起来。使用console.log(err)
可以帮助你找到它。 - dmigo