preBuild 가 appRoot 에서 돌아서 cd ../../ 로 루트로 올라가 설치하고, AMPLIFY_MONOREPO_APP_ROOT(= appRoot)1 로 앱 경로를 되짚는다.

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            # AWS Amplify 에서 모노레포 구조를 사용 할 경우 root 레벨로 올라가서 install
            - cd ../../
            - echo "$PWD"
            - yarn install
        build:
          commands:
            - echo "$PWD"
            # 현재 root로 이동한 상태이므로 $AMPLIFY_MONOREPO_APP_ROOT를 바로 참조하도록 설정
            - if [ $NODE_ENV_VARIABLES = ".env.development" ]; then cat "./$AMPLIFY_MONOREPO_APP_ROOT/$NODE_ENV_VARIABLES" > "./$AMPLIFY_MONOREPO_APP_ROOT/.env.production"; fi
            - yarn run "build:$AMPLIFY_MONOREPO_APP"
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: apps/app

Footnotes

  1. Configuring monorepo build settings - AWS Amplify Hosting: appRoot — “This key must exist, and have the same value as the AMPLIFY_MONOREPO_APP_ROOT environment variable.” ↩

`#231`