AWS Amplify Build Settings
Asked Answered
S

4

11

Using Amplify I'm having difficulty deploying a React application which I believe is due to the build settings. When trying to deploy the default build settings provided are shown below: aws build settings

I know this is incorrect and the error I find in the build logs is:

2020-05-14T00:02:22.327Z [WARNING]: !! No index.html detected in deploy folder: /codebuild/output/src568504829/src/chatterfield/

The deploy is successful except when I launch the application I receive an ERR_TOO_MANY_REDIRECTS. After I changed the baseDirectory in build settings to /client/public to point to index.html. The app appears to launch without the REDIRECT error, but nothing loads. I'm guessing this is because I am not running an npm run build command, or not loading a prebuild command. Any help would be greatly appreciated. Thank you Here is the repo this app is linked to: https://github.com/travelerr/chatterfield

Shutz answered 14/5, 2020 at 12:31 Comment(1)
why aren't you using npm/yarn build?Audi
S
8

If your react folder name is "mycoolproject", your yml will need to cd into that directory. Then run the build command. baseDirectory should be where your your final build resides.

version: 0.1
frontend:
  phases:
    preBuild:
        commands:
          - cd mycoolproject
          - npm ci
    build:
        commands:
          - npm run build
  artifacts:
    baseDirectory: ./mycoolproject/build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Also, your amplify should point to a build directory... mycoolproject/amplify/config/project-config.json

{
  "providers": [
    "awscloudformation"
  ],
  "projectName": "mycoolproject",
  "version": "3.1",
  "frontend": "javascript",
  "javascript": {
    "framework": "react",
    "config": {
      "SourceDir": "src",
      "DistributionDir": "build",
      "BuildCommand": "npm run-script build",
      "StartCommand": "npm run-script start"
    }
  }
}
Subset answered 28/12, 2022 at 2:13 Comment(1)
any idea for the needed setting for flutter web app?Provost
A
7

Change baseDirectory:/ to baseDirectory:build . It worked for me.

Annual answered 3/4, 2021 at 17:55 Comment(2)
Where am i mean't to place this file?Perquisite
@ÉricaSantos place this setting in your project root on amplify.yml or modify it through the AWS Amplify UIMariannemariano
E
7

For anyone who finds this and put their app in a folder called frontend (or anything else substitute frontend for the path to your app.

version: 0.1
frontend:
  phases:
    preBuild:
        commands:
          - cd frontend
          - npm ci
    build:
        commands:
          - npm run build
  artifacts:
    baseDirectory: ./frontend/build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
Elwira answered 11/6, 2022 at 23:37 Comment(2)
Is this yaml file in the root then in the same folder with something like a frontend and server folders?Optics
any idea for the needed setting for flutter web app?Provost
O
0

If you typically build monorepos like myself, don't miss the 'monorepo' checkbox under the branch when you're creating a new Amplify connection to github. Otherwise you won't be able to setup everything properly.

Optics answered 15/4, 2023 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.