AWS Amplify: Switch existing app to new repository?
Asked Answered
M

2

9

Question

Is there any way to point existing Amplify apps to new repositories? Failing that, is there a way to clone Amplify app settings (including Backend environments) from one app to another?

Background

I was a complete newcomer to AWS until several months ago, when I inherited responsibility for an existing set of AWS apps developed by another team.

In our AWS account, Amplify is configured to use GitLab repositories which were under the previous team's control. I got a copy of the code, but I don't have access to the repositories.

So I uploaded the code to a new Bitbucket repository, and now I need to point the existing apps in Amplify to the new repositories. My goal is to be able to push changes to my new repository and have Amplify detect those changes so the new build can be pushed.

3 Unsuccessful Solutions

I've tried approaching this problem from a few different angles.

1. Create a new app

I created a new app which points to the new repository, which proved to be very simple. But I didn't anticipate how difficult it would be to migrate settings (especially the Backend environment) from one app to the other. So I thought it might be simpler to point the existing apps at the new repository.

2. Reconnect Repository

I thought that configuring a new repository for an existing app would be relatively straightforward. Here's the procedure I followed.

  • Log into AWS Console and navigate to the Amplify service
  • From the list of apps, select the one I want to modify
  • Under "App settings", select the "General" tab
  • Click the "Reconnect repository" button

A dialog box popped up: "Reconnect your Git repository". It prompted me to select from a dropdown list of "Recently updated repositories", but that list was empty. There's no place to enter an address for a new repository, so this path seems to be a dead end.

3. Create a Connection

I tried to "Create a connection to Bitbucket" as described in AWS documentation here: https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create-bitbucket.html

But the "Developer Tools" console seems unrelated to Amplify. The connection was created successfully, but it doesn't appear in the "Recently updated repositories" list, and I don't know how else it can be used.

Monroy answered 25/9, 2022 at 5:59 Comment(0)
R
9

If you are okay with a CLI solution, have a look at the comment below from https://github.com/aws-amplify/amplify-hosting/issues/288#issuecomment-737192995

aws amplify update-app --app-id AMPLIFY_APP_ID --repository REPOSITORY_URL --access-token ACCESS_TOKEN

... worked for me, transferring from one github account to another github account and repo. I know it's not quite what the OP was doing, but thought it may be worth noting that:

  • The AMPLIFY_APP_ID is the last bit of the app ARN (e.g. dXXXXXXXXXXXXX)
  • For github repositories, the access token is a Personal Access Token (https://github.com/settings/tokens). I gave it all of the repo and admin:repo_hook privileges. That had to be created from the repository owner's account, not a contributor.

This helped me to change that app to point to a different GitHub repository.

AWS CLI requires some setup though, the documentation is available here https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html

Edit: You might also have to Reconnect The Repository using the UI after changing it using the CLI

Rodmun answered 16/11, 2022 at 5:25 Comment(3)
This however asks to delete all existing branches (in the Amplify project), so, one might as well create another project and then switch over the DNS.Danyelldanyelle
The repo had to be in the following format for me: [email protected]/organization/repositoryStrangury
I also had to run amplify push to reauthorize the backend resources.Selfdefense
E
0

Provided that you want to point it to a repo that is in different account, here's what you will do:

  • Go to the app settings in AWS Amplify.
  • Click on the General tab on the right side panel.
  • Scroll down to Branches.
  • Select the branch that you would like to be taken from the new repo.
  • Click on Actions and select disconnect the branch.
  • Then click on Connect Branch.
  • A new window will open that will say GitHub authentication successful.
  • Click on Cancel and you will be redirected to a window that will ask you to select the source code provider.
  • Open a new tab and log in to the GitHub account that you would like the amplify app to take the code from.
  • Come back to the Amplify tab and select GitHub account.

And that's it. Do the verification, select the repo and you're good to go.

Edit: First you need to disconnect all the repositories.

Estrus answered 1/5 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.