forked from ysugimoto/aws-lambda-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (28 loc) · 921 Bytes
/
index.js
File metadata and controls
31 lines (28 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Automatic Image resize, reduce with AWS Lambda
* Lambda main handler
*
* @author Yoshiaki Sugimoto
* @created 2015/10/29
*/
var ImageProcessor = require("./libs/ImageProcessor");
var Config = require("./libs/Config");
var fs = require("fs");
var path = require("path");
// Lambda Handler
exports.handler = function(event, context) {
var s3Object = event.Records[0].s3;
var configPath = path.resolve(__dirname, "config.json");
var processor = new ImageProcessor(s3Object);
var config = new Config(
JSON.parse(fs.readFileSync(configPath, { encoding: "utf8" }))
);
console.log(s3Object);
processor.run(config)
.then(function(proceedImages) {
context.succeed("OK, numbers of " + proceedImages.length + " images has proceeded.");
})
.catch(function(messages) {
context.fail("Woops, image process failed: " + messages);
});
};