AWS EB部署节点应用程序:无法运行npm install

时间:2017-05-14 21:33:27

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

我正在尝试将我的节点应用程序部署到AWS。它甚至不允许我使用eb deploy来部署应用程序(保持为Sample Application)。

版本:运行Node.js的64位Amazon Linux 2016.09 v4.0.1

日志说

  

无法运行npm install

但我不太确定他们还要求我做些什么来修复它。我可以在本地安装npm:

-------------------------------------
/var/log/eb-activity.log
-------------------------------------
  Failed to run npm install. Snapshot logs for more details.
  Traceback (most recent call last):
    File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in <module>
      main()
    File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 677, in main
      node_version_manager.run_npm_install(options.app_path)
    File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 136, in run_npm_install
      self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
    File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
      raise e
  subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm', '--production', 'rebuild']' returned non-zero exit status 1 (Executor::NonZeroExitStatus)

概述页面的快照:

enter image description here

Eb部署失败消息:

$ eb deploy
Creating application version archive "app-bdfdd-170514_152527".
Uploading: [##################################################] 100% Done...
INFO: Environment update is starting.                               
INFO: Deploying new version to instance(s).                         
ERROR: Failed to run npm install. Snapshot logs for more details.   
ERROR: [Instance: i-09af789a519075c5e] Command failed on instance. Return code: 1 Output: (TRUNCATED).../opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
    raise e
subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1. 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-09af789a519075c5e'. Aborting the operation.
ERROR: Failed to deploy application.                                

ERROR: Failed to deploy application.

我的ebextensions文件(.ebextentions/config.config),默认:

packages:
  yum:
    git: []
    cairo: []
    cairo-devel: []
    libjpeg-turbo-devel: []
    giflib-devel: []

Package.json文件

{
  "name": "live-demos",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "gulp": "gulp",
    "start": "node app.js",
    "start:dev": "browserify ./js/about.js -o ./build/js/bundle.js && gulp build-dev"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.x.x",
    "browserify": "^13.1.0",
    "canvas": "^1.4.0",
    "d3": "^3.5.17",
    "d3.layout.cloud": "^1.2.0",
    "ejs": "^2.5.1",
    "express": "^4.13.1",
    "gulp": "^3.9.0",
    "gulp-autoprefixer": "^2.3.1",
    "gulp-compass": "^2.1.0",
    "gulp-concat": "^2.6.0",
    "gulp-minify-css": "^1.2.0",
    "gulp-nodemon": "^2.0.4",
    "gulp-sass": "^2.0.4",
    "isotope-layout": "^3.0.1",
    "request": "^2.74.0",
    "request-promise": "^4.1.1"
  },
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-browserify": "^0.5.1",
    "gulp-nodemon": "^2.0.4"
  }
}

1 个答案:

答案 0 :(得分:2)

这是一个非常老的问题,但是我要在这里添加信息,因为我最近遇到了与本周相同的问题,找到解决方案和解释并不容易。

TLDR::如果您看到此错误,则很可能使用AWS最小的实例之一,并且节点在完成npm install的完整列表之前已用完内存流程。您可以通过.ebextensions配置文件分配一些交换内存来解决此问题。

将以下文件夹/文件添加到您的存储库中(或添加到现有的配置文件中),然后确保在运行eb deploy之前已对其进行跟踪和提交。

# .ebextensions/01_setup_swap.config
commands:
    01setup_swap:
        test: test ! -e /var/swapfile
        command: |
            /bin/dd if=/dev/zero of=/var/swapfile bs=1M count=2048
            /bin/chmod 600 /var/swapfile
            /sbin/mkswap /var/swapfile
            /sbin/swapon /var/swapfile

TL_did_R

我一直在使用多个Elastic Beanstalk Node应用程序来解决此问题,这些应用程序在AWS提供的最小实例类型(t2.micro,t1.micro和t3.nano)上运行。解决该错误的唯一方法是使用Immutable Deployment Policy,它花费的时间更长,并且伴随着其他各种麻烦,例如新实例ID,ssh会话重启,新日志等。

在多次搜索失败之后,我终于happened upon this post,其中用户eladnava2有效地提供了我在此处提供的相同解释和解决方案-但随后该线程中仍在询问是否有人的其他人将其忽略找到了解决方案。尽管其中包含的代码示例eladnava2对我不起作用,但它为我进行下一次搜索提供了正确的路径,其中led me to this post用于配置EB交换内存,并包括了对我有用的代码段,以及我已经在上面加上了逐字记录。尽管该博客文章是关于ruby应用程序的,但它已与Node应用程序一起为我工作。

自从几天前进行此更改以来,尽管每天有六个应用程序都在t3.nano实例上运行多次部署,但我再也没有遇到此错误。

所以……如果您要在要安装大量依赖的小型实例上运行Node应用程序-这可能只是在计算机的默认资源不足以完成构建任务时为您解决问题的方法。

上述实例的内存:

enter image description here