AWS EB deploying Node app: failed to run npm install

会有一股神秘感。 提交于 2019-12-04 07:50:33

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!