Created
April 2, 2018 22:26
-
-
Save next-marianmoldovan/d146470629b8c6429a0008396fe2ac43 to your computer and use it in GitHub Desktop.
AWS Rekognition example
This file contains hidden or 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 request = require('request').defaults({ encoding: null }); | |
const aws = require('aws-sdk'); | |
const rekognition = new aws.Rekognition({region: 'eu-west-1'}); | |
exports.handler = function(event, context, callback) { | |
request(event.url, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var params = { | |
Image: { | |
Bytes: body | |
}, | |
MaxLabels: 10, | |
MinConfidence: 0.5 | |
}; | |
rekognition.detectLabels(params, function(err, data) { | |
if(err || data.Labels.length < 1) | |
callback(err || 'No items here...'); | |
else { | |
// Opcionalmente filtramos un número de resultados | |
data = data.slice(0, 5); | |
callback(err, data); | |
} | |
}); | |
} | |
}); | |
} |
This file contains hidden or 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
{ | |
"name": "rekognition-lambda", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"aws-sdk": "^2.7.13", | |
"request": "^2.79.0", | |
"request-buffer": "^1.0.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment