AWS EB deploy Node application: failed to run npm install

I am trying to deploy my node app for AWS. It won't even allow me to deploy the app (remains as Sample Application

) using eb deployment.

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

The magazines say

Failed to run npm install

But I'm not too sure what else they are asking me to do to fix this. I can install npm 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)

      

Snapshot of overview page:

enter image description here

Eb deployment error message:

$ 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.

      

My ebextensions file (in .ebextentions/config.config

), default:

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

      

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

      

+4


source to share


1 answer


This is a pretty old question, but I am adding information here as I faced the same problem as this week and it was not easy to find a solution and explanation.

TL; DR: If you see this error, chances are you are using one of the smallest AWS instances, and the node is running out of memory before it can complete the full list of processes npm install

. You can fix this problem by allocating some swap memory via .ebextensions

config .ebextensions

.

Add the following folder / file to your repo (or add to an existing config file), then make sure it's tracked and committed before 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 :



I ran into this issue consistently with several Elastic Beanstalk Node applications running on the smallest types of AWS offerings (t2.micro, t1.micro, and t3.nano). The only way I could get around this error was to use an immutable deployment policy that takes longer and comes with all other kinds of headaches like new instance ids, ssh restart, new logs, etc.

After many unsuccessful searches, I finally ended up on this post where a user eladnava2

effectively provides the same explanation and solution that I have included here - but then ignored by the next few people in the thread who are still asking if a solution has been found. While the sample code eladnava2

didn't work for me, it set me on the right path for my next search, which led me to this post when setting up EB swap memory, and included a piece of code that worked for me and that I included verbatim. While the blog post is about ruby ​​apps, it worked for me with Node.

Since this change a couple of days ago, I have not encountered the error again, despite the fact that there were half a dozen applications running on instances over several deployments per day t3.nano

.

So ... if you are running Node applications on small instances with a lot of dependencies to install - it might just do the trick for you when the default computer resources are insufficient to complete build tasks.

Memory for the instances noted above:

enter image description here

0


source







All Articles