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.
The process is simple for new apps and that procedure is explained in the announcement. Developers who have existing apps in the same repo and want to consolidate their build settings need to make some updates.
Amplify stores application settings in the app which can be viewed and edited by going to App settings -> Build settings. The documentation for the build settings shows that monorepo apps utilize a different structure: The build settings for each application are moved into an applications array. Every application in the repository needs to be updated to use the applications array. 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
The appRoot value should contain the root directory of the application. Everything in the spec is relative to that directory, so there is no need include commands for changing directory and the baseDirectory is no longer required in this case.
To utilize consolidated build specs, the application level spec is not sufficient. Refer again to the documentation on creating the build spec for a monorepo. This should be a file that is checked into the the root of the repository. Values in the repository level spec replace those in the app spec that amplify stores.
And that's it! In summary, migrating existing monorepo projects to the supported format requires updating the application specific spec in the console and creating/modifying amplify.yml in the root of the repository.
Thanks! I misconfigured my project and been stuck for few hours, thank you