Skip to content

Instantly share code, notes, and snippets.

@johncmckim johncmckim/faceswap.js
Last active Jan 15, 2017

Embed
What would you like to do?
Emoticon Faceswap Handler
'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const logger = require('./logger');
const processor = require('./processor');
const rekognition = require('./rekognition');
const BUCKET_NAME = process.env.BUCKET_NAME;
const ALLOWED_EXTENSIONS = process.env.ALLOWED_EXTENSIONS.split('|');
// Process S3 Event Object
const getImagesFromEvent = (event) => event.Records.reduce((accum, r) => {
if (r.s3.bucket.name === BUCKET_NAME) {
const key = r.s3.object.key;
const extension = path.extname(key).toLowerCase();
if (ALLOWED_EXTENSIONS.indexOf(extension) !== -1) {
accum.push(key);
}
}
return accum;
}, []);
// Handler function that is invoked by Lambda
module.exports.handler = BbPromise.coroutine(function* (event, context, cb) {
try {
logger.log('Recieved Event', event);
const images = getImagesFromEvent(event);
logger.log('Found images on event', images);
const imageFaces = yield rekognition.detectFacesOnImages(images);
logger.log('Detected faces', imageFaces);
yield processor.processImages(imageFaces);
cb(null);
} catch (err) {
logger.log('Error', err);
cb(err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.