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.
Version: 64bit Amazon Linux 2016.09 v4.0.1 running Node.js
The logs say
Failed to run npm install
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)
A snapshot of the overview page:
Eb deploy failure 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 (at .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"
}
}
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: 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.
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:
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.
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.
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.
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.
Memory for instances noted above:
来源:https://stackoverflow.com/questions/43969008/aws-eb-deploying-node-app-failed-to-run-npm-install