node-hocus-pocus / legerdemain

Run your Node.js web apps from AWS API Gateway.
83 stars 4 forks source link

Labda Test is Failing #5

Open Vladimir85 opened 8 years ago

Vladimir85 commented 8 years ago

Hello John,

by following your documentation, to make the application work in Amazon Lambda, I have to:

var express      = require('express'),
    app          = express();

app.get('/', function (req, res) {
   console.log("Got a GET request for the homepage");
   res.send('Hello GET');
});

var server = app.listen(8080, function () {
    console.info("Server is up and running on: %s:%s", server.address().address, server.address().port);
});

module.exports = app; // <--- Make sure I'm exporting it as module
//module.exports = server; // I've tried to wire server's ref, with no luck
var legerdemain = require('legerdemain');
var app         = require('./app.js');
exports.handler = legerdemain.bind(app);

Node dependencies are:

{
  "name": "ExpressLambda",
  "version": "1.0.0",
  "description": "Amazon Lambda - NodeJS Expres Mapping",
  "main": "app.js",
  "dependencies": {
    "express": "^4.11.0",
    "legerdemain": "^0.1.1"
  },
  "author": "",
  "license": "none"
}

I've executed npm install all the dependencies has been loaded to node_modules folder, than I've zipped all the files and uploaded as Lambda's code.

After "Test" execution, I'm getting following error:

{
  "errorMessage": "connect ECONNREFUSED",
  "errorType": "Error",
  "stackTrace": [
    "errnoException (net.js:905:11)",
    "Object.afterConnect [as oncomplete] (net.js:896:19)"
  ]
}

Log file contains:

START RequestId: a007ca8e-cab3-11e5-ad3a-51d4ebbd03a5 Version: $LATEST
2016-02-03T20:20:54.192Z    unat2bjfoaqq7phk    Server is up and running on: 0.0.0.0:8080
2016-02-03T20:20:54.340Z    a007ca8e-cab3-11e5-ad3a-51d4ebbd03a5    { [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  response: undefined }
2016-02-03T20:20:54.398Z    a007ca8e-cab3-11e5-ad3a-51d4ebbd03a5    {"errorMessage":"connect ECONNREFUSED","errorType":"Error","stackTrace":["errnoException (net.js:905:11)","Object.afterConnect [as oncomplete] (net.js:896:19)"]}
END RequestId: a007ca8e-cab3-11e5-ad3a-51d4ebbd03a5
REPORT RequestId: a007ca8e-cab3-11e5-ad3a-51d4ebbd03a5  Duration: 207.58 ms Billed Duration: 300 ms     Memory Size: 128 MB Max Memory Used: 16 MB

Looks like the app is not able to invoke itself at 0.0.0.0:8080

Am I missing some in configuration?

Thanks, Vlad

Vladimir85 commented 8 years ago

I have found the issue, I have not configured the "Integration Request" and "Integration response". Not it seems to be working

nirmalgoswami commented 8 years ago

@Vladimir85 hello i am new in node js and lambda,,i am trying to implement given example by you but still no luck,documentation is very poor for this

getting following error after run api gateway url

{"errorMessage":"connect ECONNREFUSED","errorType":"Error","stackTrace":["errnoException (net.js:905:11)","Object.afterConnect [as oncomplete] (net.js:896:19)"]}

so can you explain your sentence -

I have not configured the "Integration Request" and "Integration response". Not it seems to be working

Vladimir85 commented 8 years ago

@nirmalgoswami I have changed the way to configure lambda, there is non need to spin a web server. You should start by creation a dummy lambda and than link it from Amazon API Gateway to make it reachable from the outside. Once you have a working cycle, start adding more functionality to your lambda.