いつもお世話になっております。
表題の通り、AWS ElasticBeanstalkでNode.jsアプリの起動がうまくいかないのでお力をお貸しいただければ幸いです。
詳細
AWS ElasticBeanstalkにNode.jsのアプリケーションをデプロイし、以下のようにデプロイ自体は成功します。
2020-11-23 14:26:47 UTC+0900 INFO Environment update completed successfully. 2020-11-23 14:26:47 UTC+0900 INFO New application version was deployed to running EC2 instances. 2020-11-23 14:26:38 UTC+0900 INFO Instance deployment completed successfully. 2020-11-23 14:26:33 UTC+0900 INFO Instance deployment: You didn't specify a Node.js version in the 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version. 2020-11-23 14:26:22 UTC+0900 INFO Deploying new version to instance(s). 2020-11-23 14:26:14 UTC+0900 INFO Environment update is starting.
しかし、ヘルスは重大になっており、原因を見ると以下のようなエラーが出ていました。
100.0 % of the requests are failing with HTTP 5xx. Process default has been unhealthy for 2 hours 16 minutes (Target.ResponseCodeMismatch). Following services are not running: web.
また、ログを見てみると以下のようなエラーが出ていました。(怪しい箇所抜粋)
Nov 23 05:26:38 ip-172-31-36-88 web: > together@1.0.0 start /var/app/current Nov 23 05:26:38 ip-172-31-36-88 web: > cross-env NODE_ENV=production node src/server/index.ts Nov 23 05:26:38 ip-172-31-36-88 web: sh: /var/app/current/node_modules/.bin/cross-env: Permission denied Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! code ELIFECYCLE Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! errno 126 Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! together@1.0.0 start: `cross-env NODE_ENV=production node src/server/index.ts` Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! Exit status 126 Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! Failed at the together@1.0.0 start script. Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! A complete log of this run can be found in: Nov 23 05:26:38 ip-172-31-36-88 web: npm ERR! /home/webapp/.npm/_logs/2020-11-23T05_26_38_331Z-debug.log
そのため、後述のことを試したのですが、うまくいきませんでした。
試したこと その1
ElasticBeanstalkが使っているEC2にsshでユーザー:ec2-user
でログインし、以下のコマンドで権限付与。
sudo chmod 777 /var/app/current/node_modules/.bin/cross-env
試したこと その2
node_modulesとpackage-lock.jsonを削除し、npm installしなおしてデプロイ。
試したこと その3
npm rebuildしなおしてデプロイ。
参考ファイル抜粋
package.json
"scripts": { "dev": "cross-env NODE_ENV=development nodemon src/server/index.ts --watch server", "build": "nuxt build", "start": "cross-env NODE_ENV=production node src/server/index.ts", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "test": "jest", "tsc": "tsc" },
Procfile
web: npm start
最後に
もし原因がわかる方いらっしゃいましたら教えていただけないでしょうか。
よろしくお願いいたします。
あなたの回答
tips
プレビュー