12

I'm trying to deploy a node.js app using the Amazon Elastic Beanstalk service. Following this tutorial (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.sdlc.html), I managed to deploy the app. However, once uploaded on Amazon, the application failed to start. Investigating the logs show me the following error : "Failed to run npm install".

Does anyone have a good idea of what the problem might be ? The application is working great locally.

Thanks in advance for your help!

Kevin.
  • 2,820
  • 2
  • 23
  • 21

4 Answers4

16

I was having the same issue and Kevin's solution solved the problem for me, but introduced another: New instances spawned by EB for auto-scaling also need the manual configuration. This is the modification to Kevin's method that I made to solve both issues:

Another way to solve Kevin's issue is to add the required packages to a config file for your application. Create a configuration file with the extension .config (e.g., myapp.config) and place it in an .ebextensions top-level directory of your source bundle. In order to require the openssl-devel package, include these lines in the config file:

packages:
    yum:
        openssl-devel: []

For details on where the config file goes: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_custom_container.html

And details on including packages (and more) in the config file: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

jakeorr
  • 381
  • 2
  • 11
  • I also had to add: `gcc`, `make`, `libxml2` and `libxml2-devel` to get my npm install to work, here's what the yum section in my app.config looks like: [npm install error](https://forums.aws.amazon.com/thread.jspa?messageID=437520񪴐). – shaond Mar 28 '13 at 22:01
  • 4
    Hi @sHz, I'm having this same issue again with a different project. I must have to add additional packages again, but I would really like to avoid trial and error to find the correct ones. How did you figure out the dependancies you needed? – jakeorr Apr 24 '13 at 14:08
  • Thank you @jakeorr, but doesn't this config file run after the npm installation with the packages takes place? Shouldnt we add it as a AppDeployPreHook/xxfile-name.sh file (having the prefix number to the name lower than the 50npm.sh) – asaf am Aug 17 '15 at 13:04
1

I found out what the problem was. Here is the explanation.

The reason why the npm package manager failed to install some packages was due to the fact that some packages required linux libraries to be install first (ie, OpenSSL-devel). In order to resolve this problem, I had to :

1. SSH to my EC2 instance associated with my Node.js Elastic Beanstalk instance

First, remove the "Termination Protection" on your EC2 instance (Click on your EC2 instance then look for "Change Termination Protection". Then, you need to add a "KeyPair" to the EC2 instance. For that, go to the ELB manager and edit the configuration file of your ELB application. For detailed explainations, check this link (SSH to Elastic Beanstalk instance)

2. Install the missing libraries (in my case, because the bcrypt npm package was requiring it)

sudo yum update

sudo yum install openssl-devel

Hope this helps!

Community
  • 1
  • 1
Kevin.
  • 2,820
  • 2
  • 23
  • 21
  • 1
    Exactly my issue and 100% fix. note that when adding a key-pair it is normal for eb to flag everything red and have the dashboard look like its dying until a fresh deploy has been pushed up -- after you ssh in and fix the issues. – Catalyst Nov 26 '13 at 05:58
  • 9
    If you're reading and following this, please avoid manually installing packages on elastic beanstalk instances - they won't be there when you auto scale or rebuilt an environment. Instead, follow jakeorr's answer and add the package to the .ebextensions config so it's automatically installed. – Josh Hunt Mar 16 '15 at 22:46
  • 2
    downvoted. this defeats the purpose of using EB. A newly provisioned instance will lose these changes. – Lucky Soni Aug 12 '16 at 11:25
1

I encountered this problem, and solved it by simply choosing the next bigger instance type.

doer
  • 661
  • 7
  • 5
0

I found a similar problem and for me the error was because a node package was not getting successfully installed so once when I removed that node package from my package.json because I really didn't need that, it worked!

Anurag S
  • 145
  • 1
  • 7