AWS EB部署节点应用程序:无法运行npm install [英] AWS EB deploying Node app: failed to run npm install

查看:104
本文介绍了AWS EB部署节点应用程序:无法运行npm install的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to deploy my node app to AWS. It won't even let me deploy the application (stays as Sample Application) using eb deploy.

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

Version: 64bit Amazon Linux 2016.09 v4.0.1 running Node.js

日志说

无法运行npm install

Failed to run npm install

但是我不太确定他们还要求我做些什么来解决它.我可以在本地进行npm安装:

But am not too sure what else they're asking me to do to fix it. I can npm install just fine locally:

-------------------------------------
/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)

概述页面的快照:

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),默认值:

My ebextensions file (at .ebextentions/config.config), default:

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

Package.json文件

Package.json file

{
  "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"
  }
}

推荐答案

这是一个很老的问题,但是我在这里添加了信息,因为我和本周一样遇到了同样的问题,找到解决方案和解释并不容易

This is pretty old question but I'm adding info here since I was encountering the same issue as recently as this week and finding a solution and explanation was not easy.

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

TLDR: If you're seeing this error you're most likely using one of AWS smallest instances and node is running out of memory before it can complete the full list of npm install processes. You can address this by allocating some swap memory via an .ebextensions config file.

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

Add the following folder/file to your repo (or add to an existing config file), then ensure it is tracked and committed prior to running 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节点应用程序遇到此问题,这些应用程序在AWS提供的最小实例类型(t2.micro,t1.micro和t3.nano)上运行.我可以解决该错误的唯一方法是使用不可变的部署策略,它花费的时间更长,并且还伴随着其他各种麻烦,例如新实例ID,ssh会话重启,新日志等.

I was consistently running into this issue with multiple Elastic Beanstalk Node applications running on the smallest instance types AWS offers (t2.micro, t1.micro, and t3.nano). The only way I could get around the error was to use an Immutable Deployment Policy which takes longer and comes with all other kinds of headaches like new instance IDs, ssh session restarts, new logs, etc.

经过多次搜索失败后,我最终发生在该帖子上 eladnava2有效地提供了我在此处提供的相同解释和解决方案-但随后该线程中仍在询问是否已找到解决方案的其他少数人将其忽略.尽管包含的代码示例eladnava2对我不起作用,但它为我进行下一次搜索的正确路径设置了

After many failed searches I finally happened upon this post where user eladnava2 effectively provides the same explanation and solution I have included here - but is then ignored by the next few people in the thread who are still inquiring if a solution has been found. While the code example eladnava2 included did not work for me, it set me on the right path for my next search which led me to this post on configuring EB swap memory and included a code snippet which did work for me and which I've included verbatim above. While the blog post is about ruby applications it has worked for me with Node apps.

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

Since making this change a couple days ago I have not encountered the error again despite multiple deployments per day to a half dozen apps all running on t3.nano instances.

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

So… if you're running Node apps on small instances with a lot of dependencies to install - this might just do the trick for you when the default resources of the machine are insufficient to complete the build tasks.

上述实例的内存:

这篇关于AWS EB部署节点应用程序:无法运行npm install的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆