由于缺少PostgreSQL安装,Node.js应用程序无法在AWS Elastic BeanStalk上部署

时间:2015-04-21 17:22:26

标签: node.js postgresql amazon-web-services elastic-beanstalk

我们有以下package.json文件:

{
  "name" : "DecisionsConsole",
  "version" : "0.0.0",
  "private" : true,
  "scripts" : {
    "start" : "node app.js"
  },
  "dependencies" : {
    "express" : "4.0.0",
    "cookie-parser" : "1.1.0",
    "serve-favicon" : "2.0.0",
    "morgan" : "1.1.1",
    "body-parser" : "1.3.0",
    "express-session" : "1.2.1",
    "errorhandler" : "1.0.1",
    "ejs" : "1.0.0",
    "request" : "2.34.0",
    "async" : "0.4.0",
    "lodash" : "2.4.1",
    "socket.io" : "1.0.4",
    "moment" : "~2.5.1",
    "pg" : "2.11.1",
    "connect" : "2.14.3",
    "sql" : "0.37.0",
    "request-json" : "0.4.10",
    "simplesets" : "1.2.0",
    "grunt" : "0.4.4",
    "aws-sdk" : "2.0.0-rc.19",
    "webworker-threads" : "0.4.13",
    "indexof" : "*",
    "serve-index" : "1.6.1",
    "node-rest-client" : "0.8.0",
    "querystring" : "0.2.0",
    "xml2js" : "0.4.6",
    "msexcel-builder" : "0.0.2",
    "mime" : "1.3.4"
  },
  "devDependencies" : {
    "grunt-contrib-compress" : "~0.7.0",
    "grunt-contrib-compass" : "~0.7.2",
    "grunt-contrib-uglify" : "*",
    "nodeunit" : "*"
  }
}

我们正在使用基于运行Node.js的64位Amazon Linux 2014.02 v1.0.1的AWS Elastic BeanStalk环境。它是旧环境而不是最新版本的原因是因为我们的某些软件包与较新的AWS环境之间似乎存在冲突。

部署时我们收到错误Update environment operation is complete, but with errors. For more information, see troubleshooting documentation.

经过进一步调查,我们在eb-tools.log

中发现了类似的错误
 /bin/sh: pg_config: command not found gyp: Call to 'pg_config --libdir' returned 
 exit status 127. gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with 
 exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/opt/elasticbeanstalk/node-
 install/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/
 configure.js:337:16) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:
 98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:
 797:12) gyp ERR! System Linux 3.4.73-64.112.amzn1.x86_64 gyp ERR! command "node" "/
 opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/lib/node_modules/npm/
 node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /tmp/deployment/
 application/node_modules/pg gyp ERR! node -v v0.10.26 gyp ERR! node-gyp -v v0.12.2 
 gyp ERR! not ok > webworker-threads@0.4.13 install /tmp/deployment/application/
 node_modules/webworker-threads > node-gyp rebuild make: Entering directory `/tmp/
 deployment/application/node_modules/webworker-threads/build' CXX(target) Release/
 obj.target/WebWorkerThreads/src/WebWorkerThreads.o 

我意识到它有点难以阅读,但它在eb-tools.log文件中只有一行。经过一番挖掘,我发现了这个:  Error installing node-gyp on ubuntu。但是,我不认为它是相关的。

经过进一步研究,我发现了这一点:https://github.com/brianc/node-postgres/issues/684

似乎有道理。问题是 - 如何让AWS Elastic BeanStalk自动安装PG?

3 个答案:

答案 0 :(得分:2)

它表明您没有在弹性beanstalk实例上安装postgres

  1. 从项目的根目录创建.ebextensions文件夹。
  2. 使用package.config和以下

    创建一个文件

    packages: yum: postgresql93-devel: []

  3. 然后提交您的更改
  4. 最后使用eb deploy
  5. 部署到弹性beanstalk

    然后你应该好。

    查看此链接了解更多http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html

答案 1 :(得分:0)

在Elastic Beanstalk中部署Node + PostgreSQL应用程序时遇到各种问题。首先,我收到了上述消息更新环境操作已完成,但有错误。有关更多信息,请参阅故障排除文档, 所以我不得不清理一下代码:在我的IDE(AWS自己的Cloud9)中可以正常工作的事情在EB中不起作用。例如,我在使用bcrypt时遇到问题,必须将其替换为bcrypt.js。另外,我的package.json将Node包含在依赖项中,并触发了错误。

得到一个不错的“ eb create”后,最终的答案是these instructions。请花一些时间来关注它们,因为通常的匆忙尝试和错误不太可能成功。这是因为添加数据库会增加一些复杂性,这主要是由于安全组的设置。

Here,您将找到有关使用PostgreSQL数据库设置Node.js应用程序的完整演练(在上一链接中已提到)。您有一个github存储库,可以克隆并自己进行安装。

This video by AWS people对于进一步了解EB也很有用。

祝你好运!

答案 2 :(得分:0)

可接受的答案是直接解决方案。那很好。但我强烈建议您在elasticbeanstalk中将您的nodejs应用作为docker运行。这样,无论您在何处部署,该应用程序都将以相同的方式运行。此外,您将尽早发现构建问题并进行修复。

相关问题