1

I am trying to deploy AWS lambda function and I have written code in express:

Code:

 var express = require('express');
    var bodyParser = require('body-parser');
    var lampress = require('lampress');
    var request = require('request');
    var port = process.env.PORT || 5000;
    var app = express();

    app.set('port', (port));

    // Process application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({extended: false}));

    // Process application/json
    app.use(bodyParser.json());

    // Index route
    app.get('/', function (req, res) {
        res.send('Hello! I am a Chatbot designed to help you learn  Type "begin" to start a chat! You can type "begin" at any time to return to the first menu');
    });

    // for Facebook verification
    app.get('/webhook/', function (req, res) {
        if (req.query['hub.verify_token'] === 'xyz') {
            res.send(req.query['hub.challenge']);
        }
        res.send('Error, wrong token');
    });

    // Spin up the server
     var server = app.listen(app.get('port'), function() {
       console.log('running on port', app.get('port'));
     });

    //figure out if your greeting text is working
    //need persistent menu?
    app.post('/webhook/', function (req, res) {
        getStarted();
        greetingText();
        messaging_events = req.body.entry[0].messaging;
        for (i = 0; i < messaging_events.length; i++) {

            event = req.body.entry[0].messaging[i];
            sender = event.sender.id;
            if (event.message && event.message.text) {
            //code
            }
            if (event.postback) {
            //code
            }
            console.log('********2');
        }
        res.sendStatus(200)
    });

    exports.handler = lampress(port, server);

Error:

     START RequestId: Version: $LATEST
2017-02-02T16:58:58.055Z    undefined   running on port 5000
2017-02-02T16:58:58.112Z        Error: SecurityError: Request method not allowed
    at openOnSocket (/var/task/node_modules/xmlhttprequest-socket/lib/XMLHttpRequest.js:191:13)
    at eventHandler.sendRequest (/var/task/node_modules/lampress/index.js:64:11)
    at eventHandler.handle (/var/task/node_modules/lampress/index.js:23:10)
    at /var/task/node_modules/lampress/index.js:87:13
END RequestId: e307361f-e968-11e6-b52d-7d8324fb6452
REPORT RequestId:   Duration: 99.26 ms  Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 33 MB  
RequestId:  Process exited before completing request

I have proper node_modules in place. Am I going somewhere wrong with port number and why methods are not accessible

When access the API I get:

{"errorMessage":"RequestId: xyz Process exited before completing request"}

compressed zip structure --> index.js --> node_modules folder.

package.json: "lampress": "^1.1.1"

2
  • Were you able to solve this? Commented Mar 30, 2017 at 6:12
  • This happens, this didn't stop my API to work so Ignored this error since I get this error while deployment not in the actual code. I tried to search for many resources but failed to get answer at that time, Commented Mar 30, 2017 at 15:59

2 Answers 2

0

You cannot listen on port 5000 for security reasons. You have to listen on a unix socket, like /tmp/mysock.

Sign up to request clarification or add additional context in comments.

Comments

0

REPORT (Duration: 99.26 ms Billed Duration: 100 ms ).

Try to set more time for duration your code in advanced settings ->(Timeout).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.