Skip to content

Commit b98e20c

Browse files
ykethanjosefaidt
andauthored
testing info (#8279)
* testing info --------- Co-authored-by: josef <[email protected]>
1 parent 38cdd49 commit b98e20c

File tree

1 file changed

+224
-2
lines changed
  • src/pages/[platform]/start/migrate-to-gen2

1 file changed

+224
-2
lines changed

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

Lines changed: 224 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{/* cspell:ignore enablegen basica acef xnibcobqircidcckd uzxgq */}
2+
13
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
24

35
export const meta = {
@@ -48,6 +50,20 @@ Please note not all resource configuration properties are supported, however the
4850

4951
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.
5052

53+
<Callout info>
54+
55+
**Testers Only**
56+
57+
Prerequisites:
58+
59+
- Node.js v18.17.1 or higher
60+
- [Local AWS CLI profile](/gen1/[platform]/start/getting-started/installation/) with `AdministratorAccess-Amplify` and the `AmplifyBackendDeployFullAccess` policies attached.
61+
- Existing Gen 1 backend or a [new Gen 1 app created](/gen1/[platform]/start/getting-started/) with some backend resources.
62+
- Git
63+
- Package manager (npm, yarn, pnpm)
64+
65+
</Callout>
66+
5167
To get started, create a new git branch and Amplify backend:
5268

5369
```bash title="Terminal" showLineNumbers={false}
@@ -64,12 +80,54 @@ amplify add env migrate
6480

6581
</Callout>
6682

83+
<Callout info>
84+
85+
**Testers Only**
86+
87+
For testing purposes, you will need to additionally install the tagged versions of the `@aws-amplify/cli` package.
88+
89+
```bash title="Terminal" showLineNumbers={false}
90+
npm install @aws-amplify/[email protected]
91+
```
92+
93+
</Callout>
94+
6795
Then push your newly-created `migrate` environment to create a set of resources matching the configuration of your live environments:
6896

97+
<Callout info>
98+
99+
**Testers Only**
100+
101+
If you have API resources, you will need to enable the following feature flag in your `amplify/cli.json` file:
102+
103+
```json
104+
{
105+
"features": {
106+
"graphqltransformer": {
107+
"enablegen2migration": true
108+
}
109+
}
110+
}
111+
```
112+
</Callout>
113+
69114
```bash title="Terminal" showLineNumbers={false}
70115
amplify push --yes
71116
```
72117

118+
Next, make a note of the stack name of your Gen 1 migrate backend, this should be in your `amplify/team-provider-info.json` file.
119+
120+
```json
121+
{
122+
"migrate": {
123+
"awscloudformation": {
124+
//... other fields
125+
"StackName": "amplify-your-app-migrate-1234567890",
126+
}
127+
}
128+
}
129+
```
130+
73131
After the push is successful, commit and push the changes to your git provider:
74132

75133
```bash title="Terminal" showLineNumbers={false}
@@ -82,28 +140,127 @@ During the migration for the new `migrate` environment, it is recommended to con
82140

83141
Next, prepare your local codebase for migration execution by running the following command:
84142

143+
<Callout info>
144+
145+
**Testers Only**
146+
147+
If you are using a names AWS CLI profile other than `default`, you will need to set the `AWS_PROFILE` environment variable to the name of the profile.
148+
149+
```bash title="Terminal" showLineNumbers={false}
150+
export AWS_PROFILE=your-profile-name
151+
```
152+
153+
then run the following command to prepare your local codebase for migration execution:
154+
155+
```bash title="Terminal" showLineNumbers={false}
156+
npx @aws-amplify/[email protected] to-gen-2 prepare
157+
```
158+
159+
</Callout>
160+
85161
```bash title="Terminal" showLineNumbers={false}
86162
npx @aws-amplify/migrate@latest to-gen-2 prepare
87163
```
88164

89165
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/).
90166

167+
91168
## Validating the preparation
92169

93170
The preparation command will add npm dependencies relevant to your Gen 2 backend in the root `package.json`. Before you begin with the validation, install dependencies:
94171

172+
95173
```bash title="Terminal" showLineNumbers={false}
96174
npm install
97175
```
98176

177+
<Callout info>
178+
179+
**Testers Only**
180+
181+
For testing purposes, you will need to additionally install the tagged versions of the `@aws-amplify/backend` and `@aws-amplify/backend-data` packages.
182+
183+
```bash title="Terminal" showLineNumbers={false}
184+
npm install @aws-amplify/[email protected] @aws-amplify/[email protected]
185+
```
186+
187+
</Callout>
188+
189+
<Callout info>
190+
191+
**Testers Only**
192+
193+
**Auth**
194+
195+
We will need to add the following manually to `backend.ts` file to set up the `Identity providers` on the `User pool client`. This is needed since Gen 2 only supports 1 user pool client out-of-the-box. Add the following code to `backend.ts` file after the `User pool client` is defined:
196+
197+
```typescript
198+
const providerSetupResult = (backend.auth.stack.node.children.find(child => child.node.id === 'amplifyAuth') as any).providerSetupResult;
199+
for (const provider in providerSetupResult) {
200+
const providerSetupPropertyValue = providerSetupResult[provider];
201+
if (providerSetupPropertyValue.node && providerSetupPropertyValue.node.id.endsWith('IDP')) {
202+
userPoolClient.node.addDependency(providerSetupPropertyValue);
203+
}
204+
}
205+
```
206+
207+
**Data**
208+
209+
If you have GraphQL API, you would need to manually input your schema in `data/resource.ts` file.
210+
211+
```typescript
212+
import { defineData } from "@aws-amplify/backend";
213+
export const data = defineData({
214+
migratedAmplifyGen1DynamoDbTableMap: [
215+
{
216+
branchName: "sandbox",
217+
modelTableNameMap: {
218+
Post: "Post-xnibcobqircidcckd2zx2uzxgq-dev",
219+
Comment: "Comment-xnibcobqircidcckd2zx2uzxgq-dev",
220+
},
221+
},
222+
],
223+
schema: `
224+
// Copy your Gen 1 schema here
225+
`,
226+
});
227+
```
228+
229+
</Callout>
230+
231+
99232
{/* how to handle the thrown errors in the code */}
100233
{/* porting custom resolvers, overridden resolvers */}
101234
{/* porting custom resources themselves */}
102235

236+
<Callout info>
237+
238+
In order to provide a smoother experience with the migration tooling, we have added `throw new Error` messages to the generated code. This is to ensure that resources requiring manual changes are modified in your sandbox environment before the migration is executed.
239+
240+
For example, if you have a Node.js Lambda function in Gen 1, you will see the following error in your sandbox run:
241+
242+
```bash title="Terminal" showLineNumbers={false}
243+
Source code for this function can be found in your Amplify Gen 1 Directory. See .amplify/migration/amplify/backend/function/app81ff331aPostConfirmation/src
244+
```
245+
246+
you will need to copy the code from your Gen 1 backend and make any necessary changes to the code such as updating to TypeScript and updating the import statements.
247+
248+
**Note:** You will need to install the Lambda dependencies in the project root `package.json` file.
249+
250+
</Callout>
251+
103252
```bash title="Terminal" showLineNumbers={false}
104253
npx ampx sandbox
105254
```
106255
256+
<Callout info>
257+
258+
If you have not deployed a Amplify Gen 2 backend before, the process will redirect you the Amplify Console to bootstrap your AWS account and region. Ensure you are signed in with Admin credentials.
259+
260+
If you experience any errors, refer to the [troubleshooting section]([platform]/build-a-backend/troubleshooting/).
261+
262+
</Callout>
263+
107264
```bash title="Terminal" showLineNumbers={false}
108265
npx ampx sandbox delete --yes
109266
```
@@ -116,6 +273,22 @@ git push
116273
117274
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.
118275
276+
<Callout info>
277+
278+
**Testers Only**
279+
280+
Deploy a new Amplify App with your repository and select the `migrate` branch.
281+
282+
<Video src="/images/gen2/getting-started/react/deploy.mp4" description="Video - Deploy the starter app" />
283+
284+
</Callout>
285+
286+
Next, make a note of the stack name of your Gen 2 backend, you can find this in the build logs or the CloudFormation stack console:
287+
288+
1. Open the [CloudFormation stack console](https://console.aws.amazon.com/cloudformation/).
289+
2. Find the stack with the Amplify AppID. The name should be in the format `amplify-<app-id>-<branch-name>-<random-id>`
290+
3. Make a note of the stack name.
291+
119292
{/* picture of amplify console connecting new `migrate` branch */}
120293
121294
{/* how to handle CDK bootstrap */}
@@ -129,19 +302,70 @@ In order to execute the migration you will need to first deploy the Amplify Gen
129302
130303
## Executing migration
131304
305+
<Callout info>
306+
307+
**Testers Only**
308+
309+
```bash title="Terminal" showLineNumbers={false}
310+
npx @aws-amplify/[email protected] to-gen-2 execute \
311+
--from <amplify-gen-1-stack-name> \
312+
--to <amplify-gen-2-stack-name>
313+
```
314+
315+
</Callout>
316+
132317
```bash title="Terminal" showLineNumbers={false}
133318
npx @aws-amplify/migrate@latest to-gen-2 execute \
134319
--from <amplify-gen-1-stack-name> \
135320
--to <amplify-gen-2-stack-name>
136321
```
137322
323+
## Reverting the migration
324+
325+
<Callout info>
326+
327+
**Testers Only**
328+
329+
```bash title="Terminal" showLineNumbers={false}
330+
npx @aws-amplify/[email protected] to-gen-2 revert \
331+
--from <amplify-gen-2-stack-name> \
332+
--to <amplify-gen-1-stack-name>
333+
```
334+
335+
</Callout>
336+
337+
```bash title="Terminal" showLineNumbers={false}
338+
npx @aws-amplify/migrate@latest to-gen-2 revert \
339+
--from <amplify-gen-2-stack-name> \
340+
--to <amplify-gen-1-stack-name>
341+
```
342+
343+
Then copy the `amplify/` directory from the `.amplify/migration` directory back into your project.
344+
345+
138346
## Post-migration tasks
139347
140348
{/* a note about s3 bucket names */}
141349
{/* ... anything else */}
142350
{/* set up CI/CD */}
143351
{/* deploy using backend-cli manually (for those not using Amplify to deploy today) */}
144352
353+
<Callout info>
354+
355+
**Testers Only**
356+
357+
Delete Cognito User pool custom domain from `amplify/backend.ts` as the domain already exists (This will not delete the domain from Cognito User pool):
358+
359+
```typescript
360+
delete (backend.auth.stack.node.children.find(child => child.node.id === 'amplifyAuth') as any).domainPrefix;
361+
```
362+
363+
Open `.amplify/migration/README.md` and follow the instructions to complete the post-migration tasks.
364+
365+
Then redeploy the application by committing the changes to Git.
366+
367+
</Callout>
368+
145369
## Verify continuous deployment
146370
147371
After performing the post-migration tasks, commit your changes and allow your deployment pipeline to deploy changes without error.
@@ -355,5 +579,3 @@ The tables below present a feature matrix for Gen 1 customers who are considerin
355579
| Interactions| Yes| Yes with custom CDK
356580
357581
</InlineFilter>
358-
359-

0 commit comments

Comments
 (0)