Created
September 6, 2018 12:31
-
-
Save kolserdav/8bbd479c0a3dc01f3d674c288dbadf6e to your computer and use it in GitHub Desktop.
NodeJs server
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
//Lambda Function Code | |
exports.handler = (event, context, callback)=>{ | |
callback(null, JSON.stringify(event.result)); | |
}; |
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
//Request to server | |
const request = require('request-promise'); | |
const options = { | |
method: 'GET', | |
uri: 'http://127.0.0.1:3000' | |
} | |
request(options) | |
.then(function (response) { | |
console.log(response) | |
}) | |
.catch(function (err) { | |
console.error((err)) | |
}) |
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
//Server code | |
const http = require('http'); | |
const lambda = require('./index'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200; | |
res.setHeader('Content-Type', 'application/json'); | |
lambda.handler({"result": "Hello Server!"}, '', (n, end)=>{res.end(end)}); | |
}); | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment