Migrate project to another AWS Account
Which Category is your question related to? Installation
What AWS Services are you utilizing? Amplify CLI, Cognito, React Frontend, Backend CRUD(APIGateway+RestrictedToCognitoUsers+Lambda+DynamoDB)
Provide additional details e.g. code snippets I need to move my amplify setup to another AWS account. How can I do that without repeating all the amplify cli commands and menus I already went through?
I copied the repo to a new folder and ran amplify init, amplify configure and amplify configure project. My web browser was already logged into the AWS console with a user in the destination AWS account so it picked that up ok to add a new amplify user account. It saved the new credentials in `amplify/.config.
But amplify push just fails as it tries to access the resources defined in the cloudformation files which all still point to the source AWS account.
⠴ Fetching updates to backend environment: dev from the cloud.(node:27698) UnhandledPromiseRejectionWarning: AccessDenied: Access Denied
Hey @alexladerman, this particular question would be better suited for the Amplify CLI. I'll transfer this issue there for better exposure.
@alexladerman Follow these steps to clone all the aws resources in the new account:
- in the original dev box, push the project to a codebase repo, respect what's in the .gitignore file.
- in the dev box that you are going to use the new account for development, set up the user credentials by executing
amplify config, and create a profile named 'newAccountProfile`. - pull down the codebase from the repo, remove the file
amplify/team-provider-info.jsonfile. - execute
amplify initand when prompted, select the 'newAccountProfile` profile. - execute
amplify push
Or if you just want to access the same resources in the original account from another account, set up an IAM role for that, you can follow this document.
Is the cli meant to be used separately from git deployment? I have the repo connected to domain deployment in AWS amplify web console and I also type "amplify publish -c". But those appear to be two separate things, am I right? does a build triggered by git push do the same as publish?
Amplify console uses Amplify CLI and it provides a "git-based" CICD for your project. The CLI command "amplify publish -c" is a combo command, it carries out the following steps in sequence. It is not tied to the Amplify Console.
- "amplify push"
- execute frontend build command
- upload frontend build command artifacts to hosting bucket
@alexladerman Follow these steps to clone all the aws resources in the new account:
- in the original dev box, push the project to a codebase repo, respect what's in the .gitignore file.
- in the dev box that you are going to use the new account for development, set up the user credentials by executing
amplify config, and create a profile named 'newAccountProfile`.- pull down the codebase from the repo, remove the file
amplify/team-provider-info.jsonfile.- execute
amplify initand when prompted, select the 'newAccountProfile` profile.- execute
amplify pushOr if you just want to access the same resources in the original account from another account, set up an IAM role for that, you can follow this document.
I was quick to thumbs-down this post when I tried and the creation process failed. I then tried to recreate my entire stack and found that it still failed. Upon closer inspection (in CloudWatch), I saw that while creating the stack it failed to find the user pool that should have been created in an earlier step. I then realized that the user pool it tried to find was the one from the other AWS account. That is not good at all. Meanwhile, since I later blew away all the amplify files, nowhere was the old user pool ID mentioned. Not good.
- delete amplify directory from the root directory.
- delete aws-exports.js from the src directory.
- RUN
amplify configure - RUN amplify init
- RUN
amplify add authoramplify add hostingetc - RUN
amplify push&lify publish
Reading the above it sounds like an amplify project is not account agnostic - it, and the files that by default are committed to revision control (ie are not in .gitignore) are tightly coupled to an existing AWS account.
Is this the intent?
@davegravy The Amplify project and the CloudFormation files generated by the CLI are account agnostic. One way to migrate or clone your project infrastructure is my creating a new environment (amplify env add)-> choose AWS profile of the new account when creating the environment -> amplify push.
@davegravy The Amplify project and the CloudFormation files generated by the CLI are account agnostic. One way to migrate or clone your project infrastructure is my creating a new environment (amplify env add)-> choose AWS profile of the new account when creating the environment -> amplify push.
Ok then is it fair to say that:
amplify/team-provider-info.jsonshould be in .gitignore, and- running
amplify initon a freshly cloned project then choosing an AWS profile associated with a blank account should create all the necessary resources in that account (it doesn't, it tries to import those which existed on the old account, as eluded to by @rt-demetri)
Having the same issue as @davegravy. Don't understand why the issue is closed. I tried all the suggestions above and couldn't successfully migrate an amplify app from one AWS account to another. Anyone figure this out yet?
If I am not misunderstand, the different AWS account here means the different IAM user account under same root user. I am trying to migrate my project from my personal account to my company's. And I guess most of the discussion is based on the same root account? Didn't find a way to do it now, anybody can help?
@Steven5678231 It sounds like there are a few different things going on. My specific issue was with organizational accounts, not IAM user accounts. My client created a new sub-account for me (which was the wrong thing to do for my role) and when I tried to recreate the stack in the root account, it was still clinging to the user pool initially created in my own account. So it saw it when it came to deciding whether to (re)create it or not but then it couldn't see it when it came time to reference it as a dependency for another Amplify resource. That's a scoping issue there somewhere.
Since I blew away my setup, I didn't get to try @alexladerman's approach (which may in fact work or may run into the same issue I experienced with the sub-account but across regions).
Finally, you have @eliasdiek's suggestion which is to start from scratch which I ended up doing twice (once for moving across accounts, once for moving to a different region). Word to the wise: record how you created the stack and save that with your project code. You don't want to revisit the stack months later and wonder "wait, what option(s) did I choose??".
@alexladerman I was facing same issue. I've to create production resources in different AWS account so I could not find any solution, but then I accidentally landed on this page https://haverchuck.github.io/docs/cli/multienv#team-members-working-on-their-own-sandbox-environments-recommended
where following steps worked for me. I committed all changes, switched to a new branch and follow these steps. I did not cloned the code so I started with
amplify init
existing environment? No
New Environment name? Prod
Then it asked me to configure few things like Confirmation email title, redirection url etc (which makes sense since new environment will have different values for these params)
After pushing changes amplify push, created all resources in new account. Luckily with no issue :)
git clone <git-repo>
$ cd <project-dir>
$ git checkout -b mysandbox
$ amplify init
? Do you want to use an existing environment? No
? Enter a name for the environment mysandbox
// Rest of init steps
// Add/update any backend configurations using amplify add/update <category>
$ amplify push
$ git push -u origin mysandbox
Here is what worked for me, extending on @zohaib-enquizit message above. This took me an hour and a half, will take less/more time depending on your setup complexity.
- Clone your repo
git clone <git-repo>
$ cd <project-dir>
$ git checkout -b mysandbox
-
Rename
amplifyfolder toamplify-old -
Run
amplify configure, create a new profile with your new AWS account. This way, you are logged in to the new AWS account. -
Run
$ amplify init
? Do you want to use an existing environment? No
? Enter a name for the environment mysandbox
// Rest of init steps
Now you have a fresh amplify project, with a mysandbox environment. When asked at any point to use an amplify profile, choose the new profile you created on step 3 so that all resources are associated with your new AWS account.
-
Run
amplify add auth,amplify add api,amplify add storage, etc to add "vanilla" resources matching all the resources you had before -
Using your IDE/code editor, or another tool (I use Webstorm) compare diff files from the amplify-old folder and fresh amplify folder. What you should see is that names of references, variables, resources etc have changed (e.g. many names are a random series of numbers and letters). Also, many variables will point now to your new AWS account for roles, policies, resource names, etc.
What you should do (this is what I did) is copy over your custom configuration using the diff tool in your editor. For example, I have a lot of customization in for auth versus the "vanilla" auth template amplify adds, so I used the diff tool to copy my password policy config, and other such settings.
Another obvious thing to copy is custom lambda functions, or your graphql schema.
When finished copying configurations, your amplify and amplify-old folders should be almost identical (all configurations are the same) but the variables that refer to names of resources, policies etc are different.
In my experience, this is the fact that makes the amplify folder not account agnostic. A lot of the configurations are indeed account agnostic (e.g. the schema file) but all the cloudformation templates are full of hardcoded references to resources. When I tried simply using my old amplify folder with a new AWS account, I got errors when pushing because amplify was trying to create/access resources in my old AWS account.
- When satisfied with editing, run
amplify pushand when everything works, you can delete your amplify-old folder.
I wish this was easier, maybe there is an easier way I overlooked, but this was the only solution I found in my case after trying many other suggestions posted in this project issues page.
hope this helps, use this at your own risk, I'm not claiming it will work for every project setup, but it worked for me.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.
Now that this issue is locked, any follow-up discussion should be directed to https://github.com/aws-amplify/amplify-cli/issues/7910.