Skip to content

Instantly share code, notes, and snippets.

@swaminator
Forked from gwryssekk/intro.md
Last active November 2, 2022 06:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swaminator/3f2e400675f3322ed76bad82a59b393b to your computer and use it in GitHub Desktop.
Save swaminator/3f2e400675f3322ed76bad82a59b393b 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.

Let's assume you have two Amplify apps - app1 and app2 that belong to your monorepo.

  1. If you have an amplify.yml file in your repo, rename it to amplify-old.yml to back it up.
  2. 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
  1. Do the same thing for app2
  2. Now commit code to your repo. This will trigger a build in both apps and each app will now get the latest buildspec definition.
  3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment