そもそものよくある問題は次の参考サイトへ
Windowsでのgulp-zipが問題?
Windowsでgulp-zipをした際に、Cannot find moduleが出ます。
シンプルにモジュール1つで試してみましたが、ダメでした。
コンソールからテスト
{ "errorMessage": "Cannot find module 'moment'", "errorType": "Error", "stackTrace": [ "Function.Module._load (module.js:417:25)", "Module.require (module.js:497:17)", "require (internal/module.js:20:19)", "Object.(/var/task/index.js:2:16)", "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)" ] }
テスト実行時のCloudWatchのログは
Unable to import module 'index': Error at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.(/var/task/index.js:2:16) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)
indexなのかrequireのmoduleなのか。
だいたいがhandler名の問題だが…
// hello.js exports.world = (event, context, callback) => { // }
だとhello.worldで呼ぶべき、ともありますが、今回そんな感じではなさそう。
上記にも引用した AWSのLambdaで、zipにしたコードを動かす時にハマったこと - console.lealog(); に従って、WindowsのGit Bashで chmod +x index.js してみたが、うまくいかない。
Macだとうまくいくんだけど…う〜ん。。
ん、もしや…!?
WindowsだとダメでMacだとうまくいく
Windowsでnpm run make
zipアップ⇒だめ。
S3アップ⇒だめ。
Macでnpm run make
zipアップ⇒とおる。
gulp-zip ぁゃしぃ。。。
.pipe(zip('simple-lambda.zip', { compress: false })) を試す。
⇒変わらずエラー
7-Zip(圧縮・解凍ソフト 7-Zip)で圧縮
⇒成功
ますます gulp-zip ぁゃしぃ。。。
これで解決
gulp
.src(['src/**'], { nodir: true, dot: true })
.pipe(zip('simple-lambda.zip'))
.pipe(gulp.dest('build/'));
nodirとdotの指定が必要でした。