aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
158 stars 53 forks source link

Change GitHub Repository for Amplify Project Without Creating a New App #1789

Open ferrivitor opened 1 month ago

ferrivitor commented 1 month ago

Environment information

Im using Amplify gen2 to backend and hosting and webapp in Flutter

Description

Hi! I need to change the GitHub repository my Amplify project uses because I am moving it from my personal profile to my organization’s profile. I have not found a way to do this without creating a new app.

Is there a way to change the linked GitHub repository for an existing Amplify project without starting a new app from scratch?

Jay2113 commented 1 month ago

Hi @ferrivitor 👋 , thanks for reaching out. In scenarios where you need to change the repository associated with an existing AWS Amplify application, our general recommendation is to create a new Amplify app. However, if you absolutely need to switch the repository on an existing application, I would recommend testing the following flow on a non-production application first:

You can leverage the update-app API for this use case.

Prerequisite: Amplify GitHub app must be installed in the target GitHub organization

aws amplify update-app --app-id <app_id_value> --repository <new_repository_url> --access-token <github_personal_access_token>

Replace the placeholders with the appropriate values:

Please note that switching the repository for an existing Amplify app is not a recommended practice and may lead to unexpected behavior or issues. It's generally safer to create a new Amplify app and associate it with the desired repository.

ferrivitor commented 1 month ago

Hi Jay! Is this solution viable for gen2 apps too?

Thanks in advance!

Jay2113 commented 1 month ago

Yes, its applicable to all Amplify apps (Gen 1 and 2).

davidmstirn commented 1 month ago

Hi! I tried these steps after renaming my existing GitHub repository and it broke branch auto deployments. I even tried deleting the Amplify GitHub app from the repo and reconnecting, and deleting the linked branches in amplify and reconnecting them. I now have no way of deploying my amplify app. Any recommendations (other than creating a new amplify app)?

Hi @ferrivitor 👋 , thanks for reaching out. In scenarios where you need to change the repository associated with an existing AWS Amplify application, our general recommendation is to create a new Amplify app. However, if you absolutely need to switch the repository on an existing application, I would recommend testing the following flow on a non-production application first:

You can leverage the update-app API for this use case.

Prerequisite: Amplify GitHub app must be installed in the target GitHub organization

aws amplify update-app --app-id <app_id_value> --repository <new_repository_url> --access-token <github_personal_access_token>

Replace the placeholders with the appropriate values:

  • : The ID of the existing Amplify app you want to update.
  • : The URL of the new repository you want to associate with the app.
  • : A GitHub personal access token with appropriate permissions to access the new repository.

Please note that switching the repository for an existing Amplify app is not a recommended practice and may lead to unexpected behavior or issues. It's generally safer to create a new Amplify app and associate it with the desired repository.