It was recently announced that AWS Amplify now has built in support for monorepos. Customers who had previously used manual commands in their applications build settings are now able to trigger builds in various apps can now consolidate all of their app settings in a single file at the root of the repository.
Let's assume you have two Amplify apps - app1 and app2 that belong to your monorepo.
- If you have an
amplify.yml
file in your repo, rename it toamplify-old.yml
to back it up. - Go to the app1 in the Amplify console, App settings > build settings and update your buildspec to the new version. For example, a simple app with the following build spec:
version: 1
frontend:
phases:
preBuild:
commands:
- cd app1
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: app1/build
files:
- '**/*'
cache:
paths: []
Needs to be converted to
version: 1
applications:
- frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: /
files:
- '**/*'
cache:
paths: []
appRoot: app1
- Do the same thing for app2
- Now commit code to your repo. This will trigger a build in both apps and each app will now get the latest buildspec definition.
- If you want to store the buildspec in your repo, add an amplify.yml file as follows:
version: 1
applications:
- frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: /
files:
- '**/*'
cache:
paths: []
appRoot: app1
- frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: /
files:
- '**/*'
cache:
paths: []
appRoot: app2