Last active
January 15, 2017 03:04
-
-
Save johncmckim/43a3fff70d108918d5095f0e7c3def8f to your computer and use it in GitHub Desktop.
Emoticon Faceswap Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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