我尝试在 AWS Elastic Beanstalk 上使用 AWS CodeBuild 启动 node.js 项目。我将环境变量放在软件配置下的 Elastic Beanstalk 配置中。之后我将我的项目部署到 Elastic Beanstalk 并且我的 server.js 没有 env 变量。
我在 server.js 的顶部实现了一个 console.log(process.env),但是我在 Elastic Beanstalk 配置中没有填写任何 env 变量。我访问了 Elastic Beanstalk 日志。
我的日志也向我展示了这一点:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
npm ERR! Linux 4.9.43-17.39.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.11.1-linux-
x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.11.1-linux-
x64/bin/npm" "run" "start"
npm ERR! node v6.11.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! xxxxxxx start: `NODE_ENV=production node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xxxxxxx start script 'NODE_ENV=production node server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the xxxxxxx package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! NODE_ENV=production node server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs xxxxxxx
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mapify-ssr
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /var/app/current/npm-debug.log