Created
September 3, 2015 14:23
-
-
Save smulube/d63c883218017874eb8a to your computer and use it in GitHub Desktop.
Example function to run on AWS lambda
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
var https = require('https'); | |
/** | |
* Pass the Github user login as `event.login`. | |
* For more information see the HTTPS module documentation | |
* at https://nodejs.org/api/https.html. | |
* | |
* Will succeed with a custom body containing just the user's name and public repos | |
*/ | |
exports.handler = function(event, context) { | |
var options = { | |
hostname: "api.github.com", | |
path: "/users/" + event.login, | |
headers: { | |
"User-Agent": "lambda test 0.0.1" | |
} | |
}; | |
var req = https.request(options, function(res) { | |
var body = ''; | |
console.log('Status:', res.statusCode); | |
console.log('Headers:', JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
console.log('Successfully processed HTTPS response'); | |
body = JSON.parse(body); | |
context.succeed({ | |
name: body.name, | |
public_repos: body.public_repos | |
}); | |
}); | |
}); | |
req.on('error', context.fail); | |
req.write(JSON.stringify(event.login)); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment