2017-11-13 5 views
0

nodeJsスクリプトがあり、実行中にスリープ状態にしたい。zipからlambda関数にエクスポートしてもスリープモジュールが選択されない

ローカルのnpmパッケージとプロジェクトを作成しました。プロジェクトディレクトリを以下に示します。

[[email protected] lambdaTestFunction]$ ls -ltr 
total 888 
drwx------. 8 ec2-user ec2-user  98 Nov 13 11:22 node_modules 
-rwxr-xr-x. 1 ec2-user ec2-user 510 Nov 13 13:51 index.js 
-rw-------. 1 ec2-user ec2-user 899230 Nov 13 13:51 index.zip 
[[email protected] lambdaTestFunction]$ 

私はzip圧縮node_modulesとindex.jsを持っているし、次の

[[email protected] lambdaTestFunction]$ cd node_modules/ 
[[email protected] node_modules]$ ls -ltr 
total 12 
drwx------. 2 ec2-user ec2-user 73 Nov 13 11:22 deasync-promise 
drwx------. 2 ec2-user ec2-user 59 Nov 13 11:22 bindings 
drwx------. 2 ec2-user ec2-user 71 Nov 13 11:22 system-sleep 
drwx------. 4 ec2-user ec2-user 4096 Nov 13 11:22 nan 
drwx------. 4 ec2-user ec2-user 4096 Nov 13 11:22 deasync 
drwx------. 3 ec2-user ec2-user 4096 Nov 13 11:22 sleep 
[[email protected] node_modules]$ 

私はスクリプトがローカルindex.js実行すると、それが動作を含んで

node_modules index.zipとして、それらをzip形式で圧縮しています次のようにします。

[[email protected] lambdaTestFunction]$ node index.js 
starting the function 
start before wait 
after 5 mins 
[[email protected] lambdaTestFunction]$ 

しかし、私はラムダ関数にzipファイルをエクスポートするとき、実行はメッセージindex.jsの

{ 
    "errorMessage": "Cannot find module 'index/node_modules/sleep'", 
    "errorType": "Error", 
    "stackTrace": [ 
    "Module.require (module.js:497:17)", 
    "require (internal/module.js:20:19)", 
    "Object.<anonymous> (/var/task/index/index.js:2:13)", 
    "Module._compile (module.js:570:32)", 
    "Object.Module._extensions..js (module.js:579:10)", 
    "Module.load (module.js:487:32)", 
    "tryModuleLoad (module.js:446:12)", 
    "Function.Module._load (module.js:438:3)" 
    ] 
} 

内容で失敗し、私は私が何かわからない

console.log("starting the function"); 
var sleep = require('sleep'); 
console.log("start before wait"); 
sleep.sleep(5); // 5 seconds 
console.log("after 5 mins"); 


exports.handler = (event, context, callback) => { 
    // TODO implement 
    //callback(null, 'Hello from Lambda'); 
    console.log("start before wait"); 
    //sleep.sleep(5); // 5 seconds 
    //    //setTimeout(function(){ alert("Hello"); }, 3000); 
    console.log("after 5 mins"); 
    callback(null, 'Hello from Lambda after 5 sec'); 

}; 

を下回っていますまだ見つかっていない。どんな助けも素晴らしいだろう。ありがとう。

答えて

0

ほとんどの場合、問題を引き起こすファイルを圧縮するためです。その代わり、

をすべてのファイルを選択する必要があり、以下のようにそれを圧縮フォルダをビュンのごnode_modulesを含むすべてのファイルとフォルダをアップロードしてくださいフォルダ

enter image description here

+0

おかげビジェイ..しかし、その後方法については、node_modules、あなたのスクリーンショットには欠けていますか?私のzipはnode_modulesとindex.jsをcontansしています... – suj

+0

あなたはnode_modulesフォルダも圧縮しなければなりません。私は外部パッケージがインストールされていないので、そこにnode_modulesフォルダはありません –

+0

node_modulesはすでに私のzipの一部です – suj

関連する問題