Skip to content

Commit 95a57c1

Browse files
committed
prose
1 parent 1905c07 commit 95a57c1

File tree

1 file changed

+65
-126
lines changed
  • src/pages/[platform]/start/migrate-to-gen2

1 file changed

+65
-126
lines changed

src/pages/[platform]/start/migrate-to-gen2/index.mdx

Lines changed: 65 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const meta = {
1616
]
1717
};
1818

19-
export function getStaticPaths () {
19+
export async function getStaticPaths() {
2020
return getCustomStaticPath(meta.platforms);
2121
}
2222

@@ -29,174 +29,113 @@ export function getStaticProps(context) {
2929
};
3030
}
3131

32-
## Starting point
32+
Amplify migration tooling is available! In this guide we will walk through how to perform migrations for your backends from Amplify Gen 1 to Amplify Gen 2. The steps you will perform will be against a new Amplify Gen 1 backend environment, and a new Amplify Gen 2 environment. After the steps are performed, you will be able to merge the migration branch onto your existing branches to individually migrate with zero downtime.
3333

34-
My app
34+
## Preparing for migration
35+
36+
The most notable change between Amplify Gen 1 backends and Gen 2 backends is the use of infrastructure as code with TypeScript. Preparing your environment for migration involves converting the configuration of your live Gen 1 backend resources to their Gen 2 equivalent written using TypeScript.
3537

36-
- main branch --> prod BE
37-
- dev branch ---> dev BE
38-
- custom domain setup
39-
- main.myapp.com and dev.myapp.com
40-
41-
## Set up migration environment
42-
43-
1. git clone my-app
44-
2. git checkout -b migrate-to-gen2
45-
3. amplify init --envName prod to initialize the app locally
46-
4. amplify env add --envName migrate to create a temporary migration env
47-
1. this should prompt for any OAuth credentials, Function env vars, secrets, etc.
48-
5. amplify push to create the new environment
49-
6. deploy `migrate-to-gen2` branch in Console and connect it to `migrate` env.
50-
7. amplify migrate to initiate the migration
51-
52-
## Generate Gen 2 codegen
53-
54-
```console title="Terminal" showLineNumbers={false}
55-
> amplify migrate
56-
You are about to migrate to Amplify Gen 2: <Docs URL>
57-
✓ Move project/amplify to project/.amplify/gen-1
58-
✓ Transforming your auth and data backend definition to Gen 2 configuration:
59-
✔ amplify/auth/resource.ts
60-
✔ amplify/data/resource.ts
61-
✔ Updating .gitignore to remove Gen1 files
62-
✔ Update package.json with Gen 2 dependencies
63-
✔ Installing @aws-amplify/backend
64-
✔ Installing @aws-amplify/backend-cli
65-
66-
Run `npx ampx sandbox` to test whether your Gen 2 backend works.
38+
To get started, create a new git branch and Amplify backend:
39+
40+
```bash title="Terminal" showLineNumbers={false}
41+
git checkout --branch migrate
6742
```
6843

69-
## Test whether Gen2 codegen works as expected in sandbox
44+
```bash title="Terminal" showLineNumbers={false}
45+
amplify add env migrate
46+
```
7047

71-
```console title="Terminal" showLineNumbers={false}
72-
> npx ampx sandbox
48+
<Callout info>
7349

74-
# starts a cloudformation deploy
50+
**Note:** at any moment up until the migration is executed on your Gen 1 and Gen 2 backends, you can revert by discarding changes tracked by git.
7551

76-
# new tab
77-
> npm run dev
52+
</Callout>
7853

79-
# starts localhost
54+
Then push your newly-created `migrate` environment to create a set of resources matching the configuration of your live environments:
8055

56+
```bash title="Terminal" showLineNumbers={false}
57+
amplify push --yes
8158
```
8259

83-
optionally run validation tool to compare resource configurations from live Gen 1 stack to CFN artifacts from Gen 2 synth
84-
85-
Now let's add an `amplify.yml` to your project. If you already have a YAML stored in the Console, go to the console and download the file and add it to the root of your project. Update the amplify.yml to look like
86-
87-
```diff title="amplify.yml"
88-
version: 1
89-
backend:
90-
phases:
91-
build:
92-
commands:
93-
- - "# Execute Amplify CLI with the helper script"
94-
- - amplifyPush --simple
95-
+ - npm ci
96-
+ - npx ampx pipeline-deploy --app-id $AWS_APP_ID --branch $AWS_BRANCH
97-
frontend:
98-
phases:
99-
build:
100-
commands:
101-
- npm run build
102-
artifacts:
103-
baseDirectory: build
104-
files:
105-
- "**/*"
106-
cache:
107-
paths:
108-
- node_modules/**/*
60+
After the push is successful, commit and push the changes to your git provider:
61+
62+
```bash title="Terminal" showLineNumbers={false}
63+
git add .
64+
git commit -m "create migration env"
65+
git push --upstream origin migrate
10966
```
11067

111-
## Now deploy the migrate-to-gen2 branch
68+
During the migration for the new `migrate` environment, it is recommended to connect the new git branch to your build system to ensure changes continuously integrate with your live environment.
11269

113-
First push this code to a Git branch
70+
Next, prepare your local codebase for migration execution by running the following command:
11471

11572
```bash title="Terminal" showLineNumbers={false}
116-
git add .
117-
git commit -m "migrate to gen2"
118-
git push -u origin migrate-to-gen2
73+
npx @aws-amplify/migrate@latest to-gen-2 prepare
11974
```
12075

121-
Now deploy the `migrate-to-gen2` branch in the Amplify Console as a new branch in the Gen 2 console. Now you should see:
76+
After this command completes successfully your `amplify/` directory is converted to an Amplify Gen 2 backend authored in TypeScript. In the next section we will walk through how to validate the generated code using [Amplify Gen 2's sandbox feature](/[platform]/deploy-and-host/sandbox-environments/setup/).
12277

123-
- main branch --> prod BE
124-
- dev branch ---> dev BE
125-
- migrate-to-gen2 branch (gen2 stack) --> migrate BE (Gen 1 CF stack)
78+
## Validating the preparation
12679

127-
- custom domain setup
128-
- main.myapp.com and dev.myapp.com and migrate-to-gen2.myapp.com (with autosubdomains enabled)
80+
{/* how to handle the thrown errors in the code */}
12981

130-
Remove backend assooication between migrate-to-gen2 branch (gen2 stack) --> migrate BE (Gen 1 CF stack)
131-
Now you have a Gen 1 backend environment called "migrate" and a Gen 2 branch called "migrate-to-gen2". Go back to your terminal and execute:
82+
```bash title="Terminal" showLineNumbers={false}
83+
npm install
84+
```
13285

13386
```bash title="Terminal" showLineNumbers={false}
134-
# some command to generate the logical ID mapping, and any other prep
135-
amplify migrate --generate-mapping --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
136-
# this --continue can error if we don't have gen 2 artifacts
87+
npx ampx sandbox
13788
```
13889

13990
```bash title="Terminal" showLineNumbers={false}
140-
# validate resource configurations between the stacks match
141-
amplify migrate --compare auth --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
142-
amplify migrate --compare auth,data,storage --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
91+
npx ampx sandbox delete --yes
14392
```
14493

14594
```bash title="Terminal" showLineNumbers={false}
146-
# some command to execute CFN stack refactoring with map
147-
amplify migrate --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
95+
git push
14896
```
14997

150-
## Apply changes to real environments
98+
## Deploying your temporary migration branch
15199

152-
1. Remove backend association in console
100+
In order to execute the migration you will need to first deploy the Amplify Gen 2 backend, scaffolded by the TypeScript code generated by the preparation command. This will create a new CloudFormation stack with live resources, which will then be used to execute the migration against to migrate resources from your Amplify Gen 1 backend stack to the new stack.
153101

154-
1. Locally checkout branch you want to migrate
102+
{/* picture of amplify console connecting new `migrate` branch */}
155103

156-
```bash title="Terminal" showLineNumbers={false}
157-
git checkout dev #apply to whatever branch
104+
{/* how to handle CDK bootstrap */}
105+
{/* how to handle updating service role BEFORE AND AFTER migrations */}
158106

159-
git merge migrate-to-gen2 -X theirs
107+
### Ensure validity of `amplify.yml`
160108

161-
git push
162-
```
109+
{/* maybe move this section up before deploying the branch -- otherwise it will likely error for frontend builds */}
110+
{/* ensure package manager is correct */}
111+
{/* tweak frontend build settings */}
163112

164-
```bash title="Terminal" showLineNumbers={false}
165-
# some command to generate the logical ID mapping, and any other prep
166-
amplify migrate --generate-mapping --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
167-
# this --continue can error if we don't have gen 2 artifacts
168-
```
113+
## Executing migration
169114

170115
```bash title="Terminal" showLineNumbers={false}
171-
# validate resource configurations between the stacks match
172-
amplify migrate --compare auth --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
173-
amplify migrate --compare auth,data,storage --from amplifymigratesoemgen1stackname --to amplify-gen1togen2-branch-12345
116+
npx @aws-amplify/migrate@latest to-gen-2 execute \
117+
--from <amplify-gen-1-stack-name> \
118+
--to <amplify-gen-2-stack-name>
174119
```
175120

121+
## Post-migration tasks
122+
123+
{/* a note about s3 bucket names */}
124+
{/* ... anything else */}
125+
126+
## Verify continuous deployment
127+
128+
After performing the post-migration tasks, commit your changes and allow your deployment pipeline to deploy changes without error.
129+
130+
{/* what happens when you experience an error */}
131+
176132
---
177133

178-
If anything fails in the flow above, customers can always run `git reset --hard HEAD` and they are back to Gen 2.
179-
180-
1. this prints a message about migrating to gen 2, including a link to migration docs
181-
2. this moves amplify/ to .amplify/gen-1 (this shouldn't be impacted by subsequent gen2 deployments)
182-
3. this codegen's gen2 backend resources — Auth, Data, Storage, Function resources
183-
4. this modifies gitignore, removes Gen 1 gitignore block, adds Gen 2 gitignore (e.g. .amplify/)
184-
1. print diff and prompt for confirmation
185-
5. this installs gen 2 tooling with package manager of choice
186-
1. print list of dependencies and prompt for confirmation
187-
2. Note: Gen 1 CLI does not have this detection built in, however we can always prompt with a list of package managers
188-
3. (see create-amplify for list of dependencies https://github.com/aws-amplify/amplify-backend/blob/main/packages/create-amplify/src/amplify_project_creator.ts#L15-L26)
189-
6. this writes amplify.yml with the default gen 2 template
190-
1. print diff and prompt for confirmation
191-
2. how do we handle existing, customized yml files?
192-
3. how do we handle complex frontend builds? should this get carried from the existing file?
193-
7. this prepares any artifacts needed for stack refactoring
194-
1. print a notice
195-
2. do we need to deploy gen 2 first?
196-
8. customer confirms changes by manually inspecting generated outputs, then commits to git
197-
9. ...
198-
199-
## Feature matrix
134+
## Migrating from Gen 1 to Gen 2
135+
136+
My app
137+
138+
## Gen 1 vs. Gen 2 feature matrix
200139

201140
The tables below present a feature matrix for Gen 1 customers who are considering Gen 2 for their apps. This will help determine the support availability for various features.
202141

0 commit comments

Comments
 (0)