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

Page updated May 3, 2024

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. From the Amplify console, go to your App overview page, select Build settings under the Hosting for viewing your app's build specification YAML file.

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

Update the build settings for the backend phase to run npx ampx generate outputs --branch dev app-id $AWS_APP_ID to generate the amplify_outputs.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. Update the build settings for the backend phase to run npx ampx generate outputs --branch dev app-id $AWS_APP_ID to generate the amplify_outputs.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.

amplify.yml
1version: 1
2backend:
3 phases:
4 build:
5 commands:
6 - 'npm ci --cache .npm --prefer-offline'
7 - 'echo $AWS_BRANCH'
8 - |
9 case "${AWS_BRANCH}" in
10 main)
11 echo "Deploying main branch..."
12 npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
13 ;;
14 dev)
15 echo "Deploying dev branch..."
16 npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
17 ;;
18 pr-*)
19 echo "Deploying pull request branch..."
20 npx ampx generate outputs --branch previews --app-id $AWS_APP_ID
21 ;;
22 *)
23 echo "Deploying to staging branch..."
24 npx ampx generate outputs --branch dev --app-id $AWS_APP_ID
25 ;;
26 esac
27frontend:
28 phases:
29 build:
30 commands:
31 - 'npm run build'
32 artifacts:
33 baseDirectory: .next
34 files:
35 - '**/*'
36 cache:
37 paths:
38 - .next/cache/**/*
39 - .npm/**/*
40 - node_modules/**/*