AWS Lambda导出类不工作
我正在使用NodeJs 6.10.2。 我正在使用2个文件
index.js
var operation = require('./Handler/opHandler').opHandler; var lambdaHandler = function () { var o = new operation(); o.deleteMessage(); } exports.lambdaHandler = function(event, context, callback) { handleSQSMessages(context, callback); };
opHandler.js
opHandler = function() { this.db = ''; } opHandler.prototype.deleteMessage = function (receiptHandle, callback) { // My code here // this.db = 'new val'; } exports.opHandler = opHandler;
在使用NodeJs 6.10的AWS Lambda上运行index.lambdaHandler时,会发生以下错误
Syntax error in module 'index': SyntaxError at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (/var/task/index.js:16:13) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10)
我GOOGLE了,发现类似的问题,但根据上面的代码应该在NodeJs 6.10工作
尝试另一种方法或模块导出。 它应该在你的情况下工作。
index.js
var operation = require('./Handler/opHandler'); var lambdaHandler = function () { var o = new operation(); o.deleteMessage(); } exports.lambdaHandler = function(event, context, callback) { handleSQSMessages(context, callback); };
opHandler.js
opHandler = function() { this.db = ''; } opHandler.prototype.deleteMessage = function (receiptHandle, callback) { // My code here // this.db = 'new val'; } module.exports = opHandler;
它解决了我的问题可能会帮助你。
- 如何将子目录path传递给GunDB S3存储驱动程序,以便可以使用非Gun数据共享相同的S3存储桶?
- 在Elastic Beanstalk上使用mongoDB部署Node.Js应用程序时出现错误
- 如何删除amazon s3文件w / nodejs /angular
- 在Elastic Beanstalk单实例上configurationSSL
- aws lambdaerror handling
- 如何使用AWS JavaScript SDK(dynamoDB)处理UnprocessedItems?
- AWS Lambda – 奇怪的堆栈跟踪
- Node.js + socket.io确定每个实例的最大客户端数量
- 如何将canvas数据上传到亚马逊S3服务器