Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 6, 2024

Monorepo setup

Some teams choose a monorepo approach, or single repositories that contain multiple packages or components to simplify the deployment process for shared libraries and components. Without a monorepo, you have to deploy each package individually, keep track of package versions and dependencies across packages, and ensure version compatibility. This can become exponentially more complex as the number of packages grows. With a monorepo, all packages and dependencies are contained within a single repository.

Amplify Gen 2 supports monorepo workflows for fullstack builds with monorepo tools such as Nx and yarn workspaces. When building with Gen 2, we recommend creating the amplify/ folder in a shared workspace. We will use the following example for this guide:

1├── apps/
2│ ├── admin-dashboard/
3│ │ ├── next.config.mjs
4│ │ └── package.json
5│ └── marketing-site/
6│ ├── astro.config.mjs
7│ └── package.json
8├── packages/
9│ └── my-shared-backend/
10│ ├── amplify/
11│ │ ├── auth/
12│ │ │ └── resource.ts
13│ │ ├── data/
14│ │ │ └── resource.ts
15│ │ └── backend.ts
16│ |── package.json
17 └── tsconfig.json
18└── package.json

Monorepos require a slightly different setup. We are going to deploy 3 Amplify apps:

  1. my-shared-backend
  2. admin-dashboard
  3. marketing-site

Deploy backend app

The first app, my-shared-backend, will be the only app that updates changes to the backend. The other apps will only run frontend builds that point to the shared backend.

  1. To get started, deploy the shared backend Amplify app. With Gen 2, you can now setup backend-only CI/CD apps. Navigate to the Amplify console and select Create new app.

  2. Once you connect your repository, select your monorepo project. Check the box that says My app is a monorepo and enter the path to your amplify backend.

monorepo

  1. Your build settings should be automatically detected. Save and deploy.

Deploy frontend apps

  1. For the frontend apps, connect the frontend projects in the Amplify console separately, and update the build commands to include:
Terminal
npx ampx generate outputs --branch main --app-id BACKEND-APP-ID
  • To locate the App ID for your backend application, navigate to the Amplify console and select your backend-app. On the Overview page, the App ID is displayed under the project name.