Skip to content

Instantly share code, notes, and snippets.

@lcasartelli
Created April 14, 2016 17:46
Show Gist options
  • Save lcasartelli/ff297e1265bb2a02221d35aa30c25ef7 to your computer and use it in GitHub Desktop.
Save lcasartelli/ff297e1265bb2a02221d35aa30c25ef7 to your computer and use it in GitHub Desktop.
Lambda code for simple demo with Microsoft Emotion API
const request = require('request');
const POX_EMOTION_API_KEY = '6aad043727374c6d9d7d010eb82f1275'
const exampleImage = 'https://thoughtcatalog.files.wordpress.com/2014/07/harry-potter-and-the-deathly-hallows-trailer-hits-the-web-video-6f199ae35b.jpg';
const handler = exports.handler = (event, context, callback) => {
request({
method: 'POST',
body: JSON.stringify({ "url": exampleImage }),
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': POX_EMOTION_API_KEY,
},
url: 'https://api.projectoxford.ai/emotion/v1.0/recognize',
}, function (err, resp, body) {
if (err) {
console.error('Failed retrieving emotion data', err.message, err.stack);
return callback(err);
}
return callback(null, body);
});
};
handler({}, {}, (err, data) => {
if (err) {
console.error('lambda failed with err', err.message, err.stack);
throw err;
}
console.info('lambda completed with data', data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment