Page updated Nov 20, 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.

share-resources

You can update your app build settings to share resources across branches. In the Amplify console, navigate to your build settings from the App overview.

build-settings

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.

version: 1 backend: phases: build: commands: - nvm use 18 - npm ci - | if [ "${AWS_BRANCH}" = "main" ] || [ "${AWS_BRANCH}" = "dev" ]; then npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID else npx amplify generate config --branch dev --app-id $AWS_APP_ID fi frontend: phases: preBuild: commands: - npm ci build: commands: - npm run build artifacts: baseDirectory: .next files: - '**/*' cache: paths: - node_modules/**/*
1version: 1
2backend:
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
14frontend:
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/**/*