Skip to content

Elastic Beanstalk deployment running out of memory

0

Hi, I am running a single instance elastic beanstalk deployment on a t4g.micro instance, (Node.js 22 running on 64bit Amazon Linux 2023/6.4.0). On this I am trying to deploy a node application as a zipped archive. Whenever I do this using EB CLI, the deployment fails and on checking eb-engine.log in the instance, I see that npm install has failed with the error code 137 (which supposedly indicates a memory allocation issue). Here are the tail logs:

2024/12/17 03:12:23.936235 [INFO] Executing instruction: Use NPM to install dependencies
2024/12/17 03:12:23.936266 [INFO] use npm to install dependencies
2024/12/17 03:12:23.936305 [INFO] Getting npm verison
2024/12/17 03:12:23.936313 [INFO] Running command: npm --version
2024/12/17 03:12:24.487594 [INFO] 10.9.0

2024/12/17 03:12:24.487625 [INFO] Using npm v10
2024/12/17 03:12:24.487643 [INFO] Running command: /bin/su webapp -c npm --omit=dev install
2024/12/17 03:13:24.554074 [INFO] Killed

2024/12/17 03:13:24.563057 [ERROR] An error occurred during execution of command [app-deploy] - [Use NPM to install dependencies]. Stop running the command. Error: Command /bin/su webapp -c npm --omit=dev install failed with error exit status 137. Stderr:Killed

This failure occurs randomly. Sometimes deployment using EB CLI succeeds, or deployment by uploading the code bundle from the console succeeds.

Further (In response to the AI answer below): The related deployment failures are instant and don't wait for timeout. I am already using an npm-shrinkwrap.json. And, looking at the instance metrics, I can't see them ever exceeding over 50% usage. The spike shown here happens only during deployment. Instance Memory Metrics

Please help me with this.

asked a year ago376 views
2 Answers
0

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!

answered a year ago
-1

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:

  1. 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.

  2. 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.

  3. Use a custom platform hook: Create a platform hook script that increases the swap space before deployment. This can temporarily alleviate memory pressure.

  4. 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.

  5. Split your deployment: If your application is large, consider splitting it into smaller modules and deploying them separately.

  6. 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.

  7. 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

answered a year ago
  • Deployment failure is instant and doesn't time out.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.