Skip to content

Amplify build fails with “ran out of memory” even on 8 GiB/4 vCPU instance

0

Hi everyone,

I’m hosting a React app on AWS Amplify. The build uses the default Standard compute type (8 GiB RAM / 4 vCPU). Since 16 Jun every deploy fails with:

The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.

12:42:16  Creating an optimized production build...
12:52:29  The build failed because the process exited too early.

The project is CRA-based, built with react-app-rewired.

Things I’ve tried:

  • cleared cache (rm -rf build && npm ci)
  • patched @aws-amplify/cli to 13.0.1
  • updated dependencies (npm audit fix)

Questions:

-Is the Node process still limited to ≈2 GiB heap even on an 8 GiB container? -Would adding NODE_OPTIONS="--max_old_space_size=6144" in amplify.yml be enough? -Any other tips to keep CRA builds from hitting OOM on Amplify?

Thanks!

asked a year ago545 views

1 Answer
0

The issue you're experiencing with your Amplify build failing due to memory constraints is a common problem, especially with complex React applications.

To address your questions:

  1. Yes, by default the Node process has a limited heap size that doesn't automatically use all available container memory. This is why you're seeing out of memory errors even on the Standard 8 GiB instance.

  2. Adding NODE_OPTIONS="--max-old-space-size=6144" to your amplify.yml would help, but may not completely solve the issue if your build is particularly memory-intensive. You can try setting this value, but be careful not to set it too close to the total available memory (8 GiB) as the system needs some memory for other processes.

  3. Additional tips to resolve this issue:

  • Upgrade your build instance: Amplify now offers larger build instances. You can upgrade to a Large instance (16 GiB memory, 8 vCPUs) or XLarge instance (72 GiB memory, 36 vCPUs) depending on your needs.

  • If using a larger instance, adjust your NODE_OPTIONS accordingly (e.g., --max-old-space-size=14000 for the Large instance).

  • Optimize your build cache configuration in amplify.yml. For Next.js applications, removing .next/cache/**/* from cache paths has helped some users, though this may not apply directly to your CRA app.

  • Consider splitting your build into smaller chunks if possible.

  • Review your application for memory leaks or particularly resource-intensive build steps.

The most straightforward solution would be to upgrade to a larger build instance, which you can configure through the Amplify console or using the AWS CLI.
Sources
Build container ran out of memory | AWS re:Post
Introducing Upgraded Build Instances on Amplify Hosting | Front-End Web & Mobile
get-app — AWS CLI 2.27.36 Command Reference
update-app — AWS CLI 2.27.36 Command Reference

answered a year ago

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.