[英]Error when deploying AWS lambda deployment package
I am trying to deploy AWS lambda function and I have written code in express: 我正在尝试部署AWS lambda函数,我已经用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. 我有适当的node_modules。 Am I going somewhere wrong with port number and why methods are not accessible
我是否出错了端口号以及无法访问方法的原因
When access the API I get: 访问API时,我得到:
{"errorMessage":"RequestId: xyz Process exited before completing request"}
compressed zip structure --> index.js --> node_modules folder. 压缩的zip结构 - > index.js - > node_modules文件夹。
package.json: "lampress": "^1.1.1" package.json:“lampress”:“^ 1.1.1”
You cannot listen on port 5000 for security reasons. 出于安全原因,您无法侦听端口5000。 You have to listen on a unix socket, like /tmp/mysock.
你必须在unix套接字上监听,比如/ tmp / mysock。
REPORT (Duration: 99.26 ms Billed Duration: 100 ms ).
REPORT(持续时间:99.26 ms收费持续时间:100毫秒)。
Try to set more time for duration your code in advanced settings ->(Timeout). 尝试在高级设置中设置更长的代码持续时间 - >(超时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.