- Newest
- Most votes
- Most comments
Hi Keshav,
In case you mention about you failed with the error code 137 (which supposedly indicates a memory allocation issue) during npm install, here are some my advices for you:
- Short term fix: add swap (sample)
- Long term fix (recommend): pre-build your source with CI/CD pipeline (or local), then using EB to deploy source. It's more common pattern in real life. (sample - IMPORTANT: don't skip build phase)
- Alternative solution: change to a larger instance type (higher cost)
Hope this helpful with you!
The issue you're experiencing with your Elastic Beanstalk deployment running out of memory is not uncommon, especially when using a t4g.micro instance which has limited resources. The error code 137 during the npm install process indeed indicates that the process was terminated due to insufficient memory.
This problem can occur randomly because the available memory on the instance can vary depending on other processes running at the time of deployment. Here are some suggestions to address this issue:
-
Increase instance size: Consider upgrading from t4g.micro to a larger instance type with more memory, such as t4g.small or t4g.medium. This will provide more resources for the deployment process.
-
Optimize your application: Review your package.json file and remove any unnecessary dependencies. Also, consider using --production flag or NODE_ENV=production to avoid installing dev dependencies.
-
Use a custom platform hook: Create a platform hook script that increases the swap space before deployment. This can temporarily alleviate memory pressure.
-
Implement rolling deployments: If you're deploying to multiple instances, use rolling deployments to update one instance at a time, reducing the overall memory load.
-
Split your deployment: If your application is large, consider splitting it into smaller modules and deploying them separately.
-
Use package-lock.json: Ensure you have a package-lock.json file in your project. This can speed up installations and potentially reduce memory usage.
-
Increase deployment timeout: If the deployment sometimes succeeds, try increasing the command timeout in your Elastic Beanstalk configuration to give more time for the installation process.
Remember, while these solutions can help, the most straightforward fix is often to use a larger instance type that can accommodate the memory requirements of your application and its deployment process.
Sources
Troubleshooting Elastic Beanstalk - Categories and FAQs - AWS Elastic Beanstalk
Troubleshooting issues with the EB CLI - AWS Elastic Beanstalk
AWS Elastic Beanstalk adds support for Node.js 22 - AWS

Deployment failure is instant and doesn't time out.