Skip to content

Instantly share code, notes, and snippets.

@gwryssekk
Last active April 10, 2023 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gwryssekk/bc046dbfe8438b10d2a8b0eb0afd1e11 to your computer and use it in GitHub Desktop.
Save gwryssekk/bc046dbfe8438b10d2a8b0eb0afd1e11 to your computer and use it in GitHub Desktop.
AWS Amplify - Converting Existing Monorepos to the New Supported Model

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.

@DjakaTechnology
Copy link

Thanks! I misconfigured my project and been stuck for few hours, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment