Skip to content

Instantly share code, notes, and snippets.

@next-marianmoldovan
Created April 2, 2018 22:26
Show Gist options
  • Save next-marianmoldovan/d146470629b8c6429a0008396fe2ac43 to your computer and use it in GitHub Desktop.
Save next-marianmoldovan/d146470629b8c6429a0008396fe2ac43 to your computer and use it in GitHub Desktop.
AWS Rekognition example
'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);
}
});
}
});
}
{
"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