aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
457 stars 115 forks source link

Provide settings to increase the build instance capacity #654

Open shide1989 opened 4 years ago

shide1989 commented 4 years ago

Is your feature request related to a problem? Please describe. For now the build instances are hosts with 4 vCPU, and 7GB memory.

Describe the solution you'd like I'd like to be able to increase the CPU, Memory, and maybe other settings to decrease the build time of my project.

Additional context I'm working on a +1 year project, and so far the build time has increased since we added additional features/settings to our project. The build configuration has already been optimised, but the provisionning time and build time still takes 7 to 10 minutes.

mikefrederick commented 7 months ago

Just chipping in that we will have to move our sites off Amplify due to this issue.

davidkircos commented 7 months ago

We are also going to be moving off of Amplify due to slow build times. > 15 minutes!

mauerbac commented 7 months ago

Hi @mikefrederick and @davidkircos - if you are still around ... this is not a feature we have actively in development. We are hoping to get to it in the later part of this year. However, no build should take more than 15 mins -- for both your apps can you send me your AppID so we can investigate. I'd like to understand why the build is taking a while.

Thank you

davidkircos commented 7 months ago

Our application is probably pretty atypical for what's on Amplify.

We build a large part of our code base in Rust/WASM. It takes a long time to compile and optimize Amplify. FWIW we do the identical builds on Vercel in about 6 minutes. We will probably move this process to self-hosted Github runners / manual AWS Deployments on S3/ CloudFront in the future.

On Thu, Mar 21, 2024 at 4:29 PM Matt Auerbach @.***> wrote:

Hi @mikefrederick https://github.com/mikefrederick and @davidkircos https://github.com/davidkircos - if you are still around ... this is not a feature we have actively in development. We are hoping to get to it in the later part of this year. However, no build should take more than 15 mins -- for both your apps can you send me your AppID so we can investigate. I'd like to understand why the build is taking a while.

Thank you

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-hosting/issues/654#issuecomment-2013961399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2RO7K7QY6AVIPQQNNEY63YZNNMNAVCNFSM4M3FWF22U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBRGM4TMMJTHE4Q . You are receiving this because you were mentioned.Message ID: @.***>

armenr commented 6 months ago

We need to be able to choose or configure the build instance size (CPU & Mem)...this is operations-prohibitive for us.

anubhavmalik commented 5 months ago

+1 to this. We are getting ENOMEM on our builds + the build times are very slow. Being able to customise the size of the build instance would solve our problems.

This is extremely weird that there isn't an option already.

mikefrederick commented 4 months ago

+1

devnjw commented 4 months ago

Removing the cache worked for me. However, not being able to do caching is very sad.

# Remove the following lines

    cache:
        paths:
            - '.next/cache/**/*'
            - 'node_modules/**/*'
rori4 commented 4 months ago

We will be prioritizing this feature this year. Stay tuned..

still waiting for that feature. Any updates?

armenr commented 4 months ago

For anyone waiting/getting stuck, this has worked for us:

Use SWAP as a clever workaround as per @Hernanm0g and @ash-77777.

You can use a custom build container or you can use AWS's provided build image and just put "sudo" in front of all the necessary commands. In our case, we use the AWS-provided image, and use "sudo" 👇

We do it this way:

amplify.yml

backend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS=--max-old-space-size=32768
        - bash bootstrap-build-env.sh

... rest of file

bootstrap-build-env.sh

#!/bin/bash
set -euo pipefail

echo "Setting up swap space..."
sudo fallocate -l 40G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
echo "✅  Done setting up swap space!"
echo ""

This has allowed us to get around build failures when Node complains about running out of memory! It's also helped to speed up our builds (a little) as well.

nam-truong-le commented 3 months ago

For anyone waiting/getting stuck, this has worked for us:

Use SWAP as a clever workaround as per @Hernanm0g and @ash-77777.

You can use a custom build container or you can use AWS's provided build image and just put "sudo" in front of all the necessary commands. In our case, we use the AWS-provided image, and use "sudo" 👇

We do it this way:

amplify.yml

backend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS=--max-old-space-size=32768
        - bash bootstrap-build-env.sh

... rest of file

bootstrap-build-env.sh

#!/bin/bash
set -euo pipefail

echo "Setting up swap space..."
sudo fallocate -l 40G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
echo "✅  Done setting up swap space!"
echo ""

This has allowed us to get around build failures when Node complains about running out of memory! It's also helped to speed up our builds (a little) as well.

I tried this but still get the error 😢

Swap was set up but it didn't help

4

# Executing command: export NODE_OPTIONS=--max-old-space-size=32768

25

# Executing command: bash bootstrap-amplify-build-env.sh

26

2024-07-22T06:02:54.249Z [INFO]: Setting up swap space...

27

2024-07-22T06:02:54.464Z [INFO]: Setting up swapspace version 1, size = 40 GiB (42949668864 bytes)

28

no label, UUID=f897c8e8-4bcf-4c36-9df3-bb2b107c079f

29

2024-07-22T06:02:54.526Z [INFO]: Filename Type Size Used Priority

30

/swapfile file 41943036 0 -2

31

2024-07-22T06:02:54.528Z [INFO]: ✅ Done setting up swap space!
codenimble commented 2 months ago

Just started running into this when switching from yarn to pnpm.

Removing the cache lines also fixed this for me.

mmansoor commented 2 months ago

Our builds fail randomly without any reason at all. Cache lines are removed.

We have also tried other solutions mentioned in the above comments.

This issue is open for almost 4 years now. Is there a new product feature that's coming down the road that we should wait for?

chrodin commented 2 months ago

removing cache made more deploys possible, but as @mmansoor mentioned, it just feels random what works and what doesn't. This way of working is not ok

vinodvarma24 commented 1 month ago

For anyone waiting/getting stuck, this has worked for us:

Use SWAP as a clever workaround as per @Hernanm0g and @ash-77777.

You can use a custom build container or you can use AWS's provided build image and just put "sudo" in front of all the necessary commands. In our case, we use the AWS-provided image, and use "sudo" 👇

We do it this way:

amplify.yml

backend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS=--max-old-space-size=32768
        - bash bootstrap-build-env.sh

... rest of file

bootstrap-build-env.sh

#!/bin/bash
set -euo pipefail

echo "Setting up swap space..."
sudo fallocate -l 40G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
echo "✅  Done setting up swap space!"
echo ""

This has allowed us to get around build failures when Node complains about running out of memory! It's also helped to speed up our builds (a little) as well.

As @armenr mentioned, adding sudo in front of all the commands is working. Here is our amplify.yml file if anybody want to reference in their setup.

amplify.yml

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=32768"
        - sudo fallocate -l 40G /swapfile
        - sudo chmod 600 /swapfile
        - sudo mkswap /swapfile
        - sudo swapon /swapfile
        - sudo swapon -s
        - yarn config set network-timeout 300000
        - yarn install --network-timeout 300000

    build:
      commands:
       - export GENERATE_SOURCEMAP=false
       - export INLINE_RUNTIME_CHUNK=false
       - export CI=false
       - export REACT_APP_MINIMIZE=true
       - yarn build --max-workers=2
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .npm
dPacc commented 1 month ago

Thanks to all the above answers, for any still facing the issue, here is what worked for me.

(1) Go to "Hosting" -> "Build Settings" on Amplify and edit your build settings to the following

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=32768"
        - sudo fallocate -l 40G /swapfile
        - sudo chmod 600 /swapfile
        - sudo mkswap /swapfile
        - sudo swapon /swapfile
        - sudo swapon -s
        - npm ci --legacy-peer-deps
    build:
      commands:
        - export GENERATE_SOURCEMAP=false
        - export INLINE_RUNTIME_CHUNK=false
        - export CI=false
        - export REACT_APP_MINIMIZE=true
        - npm run build --max-workers=2
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .npm

(2) You also need to change the image to Amazon 2023/2024 default (scroll down the page on built settings)

plsdev89 commented 1 week ago

I tried above solution, but got below error.

32 2024-10-09T20:54:02.016Z [INFO]: # Executing command: sudo swapon /swapfile

33 2024-10-09T20:54:02.056Z [WARNING]: swapon: /swapfile: swapon failed: Invalid argument

34 2024-10-09T20:54:02.059Z [ERROR]: !!! Build failed

35 2024-10-09T20:54:02.059Z [ERROR]: !!! Error: Command failed with exit code 255

36 2024-10-09T20:54:02.059Z [INFO]: # Starting environment caching...

37 2024-10-09T20:54:02.059Z [INFO]: # Environment caching completed
plsdev89 commented 1 week ago

Instead of sudo fallocate -l 40G /swapfile, I also tried sudo dd if=/dev/zero of=/swapfile bs=1M count=4096. Nothing worked.

dPacc commented 1 week ago

Instead of sudo fallocate -l 40G /swapfile, I also tried sudo dd if=/dev/zero of=/swapfile bs=1M count=4096. Nothing worked.

You also need to change the image to Amazon 2024/2023 default.

chasesagar commented 4 days ago

Thanks to all the above answers, for any still facing the issue, here is what worked for me.

(1) Go to "Hosting" -> "Build Settings" on Amplify and edit your build settings to the following

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=32768"
        - sudo fallocate -l 40G /swapfile
        - sudo chmod 600 /swapfile
        - sudo mkswap /swapfile
        - sudo swapon /swapfile
        - sudo swapon -s
        - npm ci --legacy-peer-deps
    build:
      commands:
        - export GENERATE_SOURCEMAP=false
        - export INLINE_RUNTIME_CHUNK=false
        - export CI=false
        - export REACT_APP_MINIMIZE=true
        - npm run build --max-workers=2
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .npm

PS: You also need to change the image to Amazon 2023/2024 default (scroll down the page on built settings)

@dPacc Worked for me

mcrysler commented 3 days ago

I've tried all these suggestions and I'm simply using the AWS Quickstart with nothing else added and its failing. PLEASE fix this asap! I was really looking forward to using Amplify again after having used it in the past but abandoning it because of issues. I was hoping this "gen 2" was better but now I can't even get past the build process. Here is the current yaml file I'm working with:

version: 1
backend:
  phases:
    build:
      commands:
        - npm ci --cache .npm --prefer-offline
        - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=32768"
        - sudo fallocate -l 40G /swapfile
        - sudo chmod 600 /swapfile
        - sudo mkswap /swapfile
        - sudo swapon /swapfile
        - sudo swapon -s
        - npm ci --legacy-peer-deps
    build:
      commands:
        - export GENERATE_SOURCEMAP=false
        - export INLINE_RUNTIME_CHUNK=false
        - export CI=false
        - export REACT_APP_MINIMIZE=true
        - npm run build --max-workers=2
  artifacts:
    baseDirectory: dist
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .npm
armenr commented 2 days ago

I've tried all these suggestions and I'm simply using the AWS Quickstart with nothing else added and its failing. PLEASE fix this asap! I was really looking forward to using Amplify again after having used it in the past but abandoning it because of issues. I was hoping this "gen 2" was better but now I can't even get past the build process. Here is the current yaml file I'm working with:

version: 1
backend:
  phases:
    build:
      commands:
        - npm ci --cache .npm --prefer-offline
        - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=32768"
        - sudo fallocate -l 40G /swapfile
        - sudo chmod 600 /swapfile
        - sudo mkswap /swapfile
        - sudo swapon /swapfile
        - sudo swapon -s
        - npm ci --legacy-peer-deps
    build:
      commands:
        - export GENERATE_SOURCEMAP=false
        - export INLINE_RUNTIME_CHUNK=false
        - export CI=false
        - export REACT_APP_MINIMIZE=true
        - npm run build --max-workers=2
  artifacts:
    baseDirectory: dist
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .npm

@mcrysler - have you changed the build image (docker build container in the pipeline) to use Amazon 2024/2023 default?

mcrysler commented 2 days ago

I am using the default Amazon image, yes.

On Sat, Oct 19, 2024 at 12:01 PM Armen Rostamian @.***> wrote:

I've tried all these suggestions and I'm simply using the AWS Quickstart https://docs.amplify.aws/react/start/quickstart/ with nothing else added and its failing. PLEASE fix this asap! I was really looking forward to using Amplify again after having used it in the past but abandoning it because of issues. I was hoping this "gen 2" was better but now I can't even get past the build process. Here is the current yaml file I'm working with:

version: 1 backend: phases: build: commands:

  • npm ci --cache .npm --prefer-offline
  • npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID frontend: phases: preBuild: commands:
  • export NODE_OPTIONS="--max-old-space-size=32768"
  • sudo fallocate -l 40G /swapfile
  • sudo chmod 600 /swapfile
  • sudo mkswap /swapfile
  • sudo swapon /swapfile
  • sudo swapon -s
  • npm ci --legacy-peer-deps build: commands:
  • export GENERATE_SOURCEMAP=false
  • export INLINE_RUNTIME_CHUNK=false
  • export CI=false
  • export REACT_APP_MINIMIZE=true
  • npm run build --max-workers=2 artifacts: baseDirectory: dist files:
    • '*/' cache: paths:
    • node_modules/*/
    • .npm

@mcrysler https://github.com/mcrysler - have you changed the build image (docker build container in the pipeline) to use Amazon 2024/2023 default?

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-hosting/issues/654#issuecomment-2424110216, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSATFERUQ6DCMSGX2N4R23Z4KM7LAVCNFSM4M3FWF22U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TENBSGQYTCMBSGE3A . You are receiving this because you were mentioned.Message ID: @.***>

repka3 commented 15 hours ago

I'm deploying an Angular 14 app and none of the above worked for me. However switching to Amazon 2024/2023 AND using this yml worked. version: 1 frontend: phases: preBuild: commands: