node.js - 部署AWS lambda部署包时出错

标签 node.js express aws-lambda

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

代码:

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

错误:

     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

我有适当的node_modules。我的端口号是否有问题以及为什么方法无法访问

当访问 API 时,我得到:

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

压缩的zip结构 --> 索引.js --> node_modules 文件夹。

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

最佳答案

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

关于node.js - 部署AWS lambda部署包时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42008247/

相关文章:

node.js - AWS Lambda : Can those event can be integrated with API Management Tools?

node.js - 使用 Entity Schema 的 TypeORM 一对多关系

javascript - 将 iFrame 高度调整为内容高度

node.js - 为单个 Controller 在 NestJs 上设置请求正文大小限制

javascript - MEAN 应用程序 - 无法在我的查找请求中使用查询

node.js - 使用单个命令进行查询和插入

node.js - 如何使用 node.js aws-sdk、cloudwatch 和 lambda 函数安排调用 API

python - 从 AWS 运行 FFmpeg

javascript - Browserify 更改依赖项的加载顺序

node.js - async wait 不适用于 Node.js gdrive API v3