Page updated Dec 18, 2023

Share resources across branches

In some instances, you may not want to deploy new resources for every branch. For example, you might want all your feature branches to point to the backend resources deployed by the dev branch so you can reuse seed data, users, and groups.

Main and dev environments, each with their own backend resources. In the dev environment, two feature branches are shown sharing the same backend resources.

You can update your app build settings to share resources across branches. In the Amplify console, select your app on the All apps page. From the App overview page, select Hosting > Build settings to view your app's build specification YML file.

The build specification YML file on the Build settings page in Amplify console.

Update the build settings for the backend phase to run npx amplify generate config --branch dev app-id $AWS_APP_ID to generate the amplifyconfiguration.json file for all branches other than main or dev. After this update, any new deployed branches will not deploy backend resources as part of the build and instead will use the deployed backend resources from the dev branch.

1version: 1
3 phases:
4 build:
5 commands:
6 - nvm use 18
7 - npm ci
8 - |
9 if [ "${AWS_BRANCH}" = "main" ] || [ "${AWS_BRANCH}" = "dev" ]; then
10 npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
11 else
12 npx amplify generate config --branch dev --app-id $AWS_APP_ID
13 fi
15 phases:
16 preBuild:
17 commands:
18 - npm ci
19 build:
20 commands:
21 - npm run build
22 artifacts:
23 baseDirectory: .next
24 files:
25 - '**/*'
26 cache:
27 paths:
28 - node_modules/**/*