部署AWS lambda部署包时出错

时间:2017-02-02 17:10:39

标签: node.js express aws-lambda

我正在尝试部署AWS lambda函数,我已经用express编写了代码:

代码:

<p>
      How are you doing?
      <br />
      <br />
      <button class='btn btn-default btn-xs pull-left'>
          Cancel
      </button>
      <button class='btn btn-danger btn-xs pull-right'>
          Confirm
      </button>
      <br />
  </p>

错误:

 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);

我有适当的node_modules。我是否在某个地方出现了错误的端口号以及无法访问方法的原因

访问API时我得到:

     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

压缩拉链结构     - &GT; index.js     - &GT; node_modules文件夹。

的package.json: “lampress”:“^ 1.1.1”

2 个答案:

答案 0 :(得分:0)

出于安全原因,您无法侦听端口5000。你必须在unix套接字上监听,比如/ tmp / mysock。

答案 1 :(得分:0)

  

REPORT(持续时间:99.26 ms,收费持续时间:100毫秒)。

尝试在高级设置中为代码设置更长的时间 - &gt;(超时)。