admin管理员组文章数量:1302406
I have uploaded a node js
express project to AWS lambda
. The following is my handler code saved as exports.js
:
const
express = require('express'),
bodyParser = require('body-parser'),
request = require('request'),
app = express().use(bodyParser.json()); // creates express http server
exports.handler = function(callback){
request('http://localhost/php-rest/api.php/routes?filter=route_short_name', function(error, response, body) {
if (!error && response.statusCode == 200) {
message = JSON.stringify(JSON.parse(body));
return callback(message, false);
} else {
return callback(null, error);;
}
});
}
app.get('/exports.handler', function(req, res) {
exports.handler(function(err, data){
if(err) return res.send(err);
res.send(data);
});
});
The handler code is separate from my app.js
file. I got the following error when I tested it on aws lambda:
{
"errorMessage": "Handler 'handler' missing on module 'exports'"
}
I have uploaded a node js
express project to AWS lambda
. The following is my handler code saved as exports.js
:
const
express = require('express'),
bodyParser = require('body-parser'),
request = require('request'),
app = express().use(bodyParser.json()); // creates express http server
exports.handler = function(callback){
request('http://localhost/php-rest/api.php/routes?filter=route_short_name', function(error, response, body) {
if (!error && response.statusCode == 200) {
message = JSON.stringify(JSON.parse(body));
return callback(message, false);
} else {
return callback(null, error);;
}
});
}
app.get('/exports.handler', function(req, res) {
exports.handler(function(err, data){
if(err) return res.send(err);
res.send(data);
});
});
The handler code is separate from my app.js
file. I got the following error when I tested it on aws lambda:
{
"errorMessage": "Handler 'handler' missing on module 'exports'"
}
Share
Improve this question
edited Aug 8, 2018 at 20:50
Nisarg
1,6417 gold badges20 silver badges31 bronze badges
asked Aug 8, 2018 at 20:47
RashikRashik
1,1542 gold badges16 silver badges36 bronze badges
2 Answers
Reset to default 8So this is your lambda function which should be there as a handler. In your code app.get() has to be handled by AWS API Gateway. because it is the method of invocation of lambda functions. You can't have the nodejs server inside the lambda function.
So the .zip file should be named as index.js since when we upload the .zip file it extracts the contents and find the handler name which we have provided. These are the .zip file contents that should be uploaded.
index.js.zip
node_modules
index.js
package.json
package-lock.json
This normally appears if you don't have an index and start function. You can define it as index in the export hander:
exports.handler = function index(event, context, callback) {
// Your start code here
}
本文标签: javascriptAWS lambda quotHandler 39handle39 missing on module 39exports39quotStack Overflow
版权声明:本文标题:javascript - AWS lambda: "Handler 'handle' missing on module 'exports'" - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741652498a2390563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论