10

I have a Nest.js (Node.js) application, and I want to deploy it on ElasticBeanstalk (Node 16 version, AL2 5.5.0). My deployment keeps failing, and I found the error in eb-engine.log.

...
2022/03/23 15:11:48.570759 [INFO] Executing instruction: StageApplication
2022/03/23 15:11:48.570846 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2022/03/23 15:11:48.570860 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2022/03/23 15:11:49.274806 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2022/03/23 15:11:49.289272 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2022/03/23 15:11:49.289292 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2022/03/23 15:11:49.289306 [INFO] The dir .platform/hooks/prebuild/ does not exist
2022/03/23 15:11:49.289311 [INFO] Executing instruction: Install customer specified node.js version
2022/03/23 15:11:49.289314 [INFO] installing specified nodejs version...
2022/03/23 15:11:49.289467 [INFO] there is no nodejs version specified in package.json, skip installing specified version of nodejs
2022/03/23 15:11:49.289476 [INFO] Executing instruction: Use NPM to install dependencies
2022/03/23 15:11:49.289484 [INFO] use npm to install dependencies
2022/03/23 15:11:49.289505 [INFO] Running command /bin/sh -c npm config set jobs 1
2022/03/23 15:11:49.574486 [INFO] Running command /bin/sh -c npm --production install
2022/03/23 15:12:06.913580 [ERROR] An error occurred during execution of command [app-deploy] - [Use NPM to install dependencies]. Stop running the command. Error: Command /bin/sh -c npm --production install failed with error signal: killed 
...

I think the error occurs when installing npm packages in production mode, but I'm really wondering why this happens. I executed npm --production install in my local computer, the installing was successful with the exactly same versions of node & npm. (Node 16.14.0, npm 8.3.1 - AL2 5.5.0 latest for now).

I want to know why this happens and how to debug more details (why npm install failed in the elastic beanstalk environment).

jeongmin.cha
  • 768
  • 8
  • 22
  • `killed` is an indication of `SIGKILL`, which most common cause is out of memory. – jordanm Mar 23 '22 at 15:30
  • Can't we just prevent `npm --production install` execution in the elastic beanstalk environment. I'm using the bitbucket pipeline to build the app. – ashen madusanka Jun 20 '22 at 20:49
  • 1
    @ashenmadusanka Use prebuild hooks to make node_modules or include some node_modules folder into your source bundle before eb is trying to isntall packages. EB will not install packages when node_modules are already ready in your source bundle. – jeongmin.cha Jun 21 '22 at 00:43

2 Answers2

14

I had the same issue, and the only way I could find to solve it was to increase the size of the instance running the application. In order for it to work, I had to use t2.medium.

You can also try increasing the swap for the EC2 instance running your app, but in my experience this made the deployment process take too long and sometimes fail. (See this answer if you want to try that approach)

6

The accepted answer DOES NOT resolve the underlying issue:

npm --production install failed with error signal: killed

It's my understandind that most of the times it means a memory leak / time out issue. And it seems to be common to npm v7+ version.

SOLUTION

  1. Create node_modules with a prebuild hook:

mkdir node_modules

In doing so, you prevent AWS to install dependencies (because the folder node_modules will already exists).

  1. Install dependencies with a predeploy hook:

npm install --omit=dev

Source (see pmoleri answer)

AWS Hooks (official documentation)

Step by Step Solution (from AWS Support)

Sugar Code
  • 25
  • 5
paulin-crtn
  • 325
  • 2
  • 9