Elastic Beanstalk:部署 Nodejs 状态已降级 以下服务未运行:web

Ric*_*han 5 amazon-web-services node.js amazon-elastic-beanstalk

我刚刚使用eb deploy并尝试使用 zip 上传,elatic beanstalk 环境显示“降级”。

我点击进去看到的日志是

Overall 
Degraded

Impaired services on all instances.

Severe
Following services are not running: web.
Run Code Online (Sandbox Code Playgroud)

我的 app.js 文件:

const express = require('express');
const app = express();

app.listen(3000, () => {
    console.log("Sever console log.")
});
Run Code Online (Sandbox Code Playgroud)

package.json内容

{
  "name": "project_api",
  "version": "1.0.0",
  "engines": {
    "node": "12.18.3"
  },
  "description": "the server side of the api",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Businsoft Limited",
  "license": "ISC",
  "dependencies": {
    "dropbox": "^5.2.1",
    "express": "^4.17.1",
    "isomorphic-fetch": "^2.2.1",
    "nodemon": "^2.0.4"
  }
}

Run Code Online (Sandbox Code Playgroud)

我认为这是 Elastic Beanstalk 最简单的开始,但不知何故它失败了。有什么想法可以解决吗?

Ric*_*han 6

经过一段时间的调试,我终于解决了这个问题。

package.json

我需要删除这一行:

"main": "app.js",
Run Code Online (Sandbox Code Playgroud)

并在“脚本”中添加“开始”,如下所示:

"scripts":
  "start": "node app.js"
Run Code Online (Sandbox Code Playgroud)

然后更新

app.listen(3000, () => {
    console.log("Sever console log.")
});
Run Code Online (Sandbox Code Playgroud)

const port = process.env.port || 3000;
app.listen(port, () => {
    console.log("Sever console log.")
});
Run Code Online (Sandbox Code Playgroud)

然后转到 AWS 控制台 > Elastic Beanstalk 的环境 > 配置 > 软件编辑 > 在环境属性中添加属性

名称port8080

最后重新上传源码,就可以了。