2017-11-15 7 views
0

NodeJs 6.10.2を使用しています。私はエラーに従うことAWSラムダエクスポートクラスが機能しない

を発生し、

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 NodeJs 6.10とAWSラムダでindex.lambdaHandlerを実行

opHandler = function() { 
    this.db = ''; 
} 
opHandler.prototype.deleteMessage = function (receiptHandle, callback) { 
    // My code here 
    // this.db = 'new val'; 
} 

exports.opHandler = opHandler; 

index.js 2つのファイル

を使用しています

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) 

私はグーグルして同様の問題が見つかりましたhereしかし、上記のコードはNodeJs 6.10で動作するはずです

+0

使用したコードをすべて貼り付けてください –

答えて

0

別の方法やモジュールのエクスポートをお試しください。あなたの場合にはうまくいくはずです。

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; 

それは私の問題は、あなたを助けることが解決しました。

関連する問題