11import MigrationReadMeGenerator from './migration-readme-generator' ;
22import fs from 'node:fs/promises' ;
3- import { CFNTemplate } from './types' ;
43
54jest . mock ( 'node:fs/promises' ) ;
65
76describe ( 'MigrationReadMeGenerator' , ( ) => {
87 const PATH = 'test' ;
9- const CATEGORY = 'auth' ;
10- const GEN1_CATEGORY_STACK_ID = 'arn:aws:cloudformation:us-east-1:1234567890:stack/amplify-testauth-dev-12345-auth-ABCDE/12345' ;
11- const GEN2_CATEGORY_STACK_ID = 'arn:aws:cloudformation:us-east-1:1234567890:stack/amplify-mygen2app-test-sandbox-12345-auth-ABCDE/12345' ;
128 const migrationReadMeGenerator = new MigrationReadMeGenerator ( {
139 path : PATH ,
14- category : CATEGORY ,
15- gen1CategoryStackId : GEN1_CATEGORY_STACK_ID ,
16- gen2CategoryStackId : GEN2_CATEGORY_STACK_ID ,
10+ categories : [ 'auth' , 'storage' ] ,
1711 } ) ;
18- const oldStackTemplate : CFNTemplate = {
19- Description : 'Gen1FooTemplate' ,
20- AWSTemplateFormatVersion : 'AWSTemplateFormatVersion' ,
21- Resources : {
22- Gen1Foo : {
23- Type : 'AWS::S3::Bucket' ,
24- Properties : {
25- Name : 'FooBucket' ,
26- } ,
27- } ,
28- } ,
29- Parameters : { } ,
30- Outputs : { } ,
31- } ;
32- const newStackTemplate : CFNTemplate = {
33- Description : 'Gen1FooTemplate' ,
34- AWSTemplateFormatVersion : 'AWSTemplateFormatVersion' ,
35- Resources : {
36- Gen2Foo : {
37- Type : 'AWS::S3::Bucket' ,
38- Properties : {
39- Name : 'FooBucket' ,
40- } ,
41- } ,
42- } ,
43- Parameters : {
44- authSelections : {
45- Type : 'String' ,
46- } ,
47- } ,
48- Outputs : { } ,
49- } ;
50- const logicalIdMapping = new Map ( [ [ 'Gen1FooUserPool' , 'Gen2FooUserPool' ] ] ) ;
5112
5213 it ( 'should initialize migration readme' , async ( ) => {
5314 await migrationReadMeGenerator . initialize ( ) ;
54- expect ( fs . writeFile ) . toHaveBeenCalledWith ( 'test/MIGRATION_README.md' , '## Stack refactor steps for auth category\n ' , {
15+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( 'test/MIGRATION_README.md' , '' , {
5516 encoding : 'utf8' ,
5617 } ) ;
5718 } ) ;
5819
5920 it ( 'should render step1' , async ( ) => {
60- await migrationReadMeGenerator . renderStep1 ( oldStackTemplate , newStackTemplate , logicalIdMapping , oldStackTemplate , newStackTemplate ) ;
21+ await migrationReadMeGenerator . renderStep1 ( ) ;
6122 expect ( fs . appendFile ) . toHaveBeenCalledWith (
6223 'test/MIGRATION_README.md' ,
63- `### STEP 1: CREATE AND EXECUTE CLOUDFORMATION STACK REFACTOR FOR auth CATEGORY
64- This step will move the Gen1 auth resources to Gen2 stack.
65-
66- 1.a) Create stack refactor
67- \`\`\`
68- aws cloudformation create-stack-refactor --stack-definitions StackName=amplify-testauth-dev-12345-auth-ABCDE,TemplateBody@=file://test/step3-sourceTemplate.json StackName=amplify-mygen2app-test-sandbox-12345-auth-ABCDE,TemplateBody@=file://test/step3-destinationTemplate.json --resource-mappings '[{\"Source\":{\"StackName\":\"amplify-testauth-dev-12345-auth-ABCDE\",\"LogicalResourceId\":\"Gen1FooUserPool\"},\"Destination\":{\"StackName\":\"amplify-mygen2app-test-sandbox-12345-auth-ABCDE\",\"LogicalResourceId\":\"Gen2FooUserPool\"}}]'
69- \`\`\`
70-
71- \`\`\`
72- export STACK_REFACTOR_ID=<<REFACTOR-ID-FROM-CREATE-STACK-REFACTOR_CALL>>
73- \`\`\`
74-
75- 1.b) Describe stack refactor to check for creation status
76- \`\`\`
77- aws cloudformation describe-stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
78- \`\`\`
79-
80- 1.c) Execute stack refactor
24+ `## REDEPLOY GEN2 APPLICATION
25+ 1.a) Uncomment the following lines in \`amplify/backend.ts\` file
8126\`\`\`
82- aws cloudformation execute-stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
83- \`\`\`
84-
85- 1.d) Describe stack refactor to check for execution status
86- \`\`\`
87- aws cloudformation describe-stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
27+ s3Bucket.bucketName = YOUR_GEN1_BUCKET_NAME;
8828\`\`\`
8929
90- #### Rollback step for refactor:
9130\`\`\`
92- aws cloudformation create-stack-refactor --stack-definitions StackName=amplify-testauth-dev-12345-auth-ABCDE,TemplateBody@=file://test/step3-sourceTemplate-rollback.json StackName=amplify-mygen2app-test-sandbox-12345-auth-ABCDE,TemplateBody@=file://test/step3-destinationTemplate-rollback.json --resource-mappings '[{\"Source\":{\"StackName\":\"amplify-mygen2app-test-sandbox-12345-auth-ABCDE\",\"LogicalResourceId\":\"Gen2FooUserPool\"},\"Destination\":{\"StackName\":\"amplify-testauth-dev-12345-auth-ABCDE\",\"LogicalResourceId\":\"Gen1FooUserPool\"}}]'
31+ s3Bucket.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplacePolicy: true });
9332\`\`\`
9433
9534\`\`\`
96- export STACK_REFACTOR_ID=<<REFACTOR-ID-FROM-CREATE-STACK-REFACTOR_CALL>>
35+ cfnUserPool.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplacePolicy: true });
9736\`\`\`
9837
99- Describe stack refactor to check for creation status
10038\`\`\`
101- aws cloudformation describe-stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
39+ cfnIdentityPool.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplacePolicy: true });
10240\`\`\`
10341
104- Execute stack refactor
10542\`\`\`
106- aws cloudformation execute- stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
43+ Tags.of(backend. stack).add("gen1-migrated-app", "true");
10744\`\`\`
10845
109- Describe stack refactor to check for execution status
46+ 1.b) Deploy sandbox using the below command or trigger a CI/CD build via hosting by committing this file to your Git repository
11047\`\`\`
111- aws cloudformation describe-stack-refactor --stack-refactor-id $STACK_REFACTOR_ID
48+ npx ampx sandbox
11249\`\`\`
113- ` ,
114- { encoding : 'utf8' } ,
50+ ` ,
11551 ) ;
11652 } ) ;
11753
118- it ( 'should render step2' , async ( ) => {
119- await migrationReadMeGenerator . renderStep2 ( ) ;
54+ it ( 'should render step1 without storage' , async ( ) => {
55+ const PATH = 'test' ;
56+ const migrationReadMeGenerator = new MigrationReadMeGenerator ( {
57+ path : PATH ,
58+ categories : [ 'auth' ] ,
59+ } ) ;
60+ await migrationReadMeGenerator . renderStep1 ( ) ;
12061 expect ( fs . appendFile ) . toHaveBeenCalledWith (
12162 'test/MIGRATION_README.md' ,
122- `### STEP 2: REDEPLOY GEN2 APPLICATION
123- This step will remove the hardcoded references from the template and replace them with resource references (where applicable).
124-
125- 2.a) Uncomment the following lines in \`amplify/backend.ts\` file to instruct CDK to use the gen1 S3 bucket (if storage is enabled) and apply retain removal policies for auth and/or storage resources
126- \`\`\`
127- s3Bucket.bucketName = YOUR_GEN1_BUCKET_NAME;
128- \`\`\`
129-
130- \`\`\`
131- s3Bucket.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplacePolicy: true });
132- \`\`\`
63+ `## REDEPLOY GEN2 APPLICATION
64+ 1.a) Uncomment the following lines in \`amplify/backend.ts\` file
13365
13466\`\`\`
13567cfnUserPool.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplacePolicy: true });
@@ -143,7 +75,7 @@ cfnIdentityPool.applyRemovalPolicy(RemovalPolicy.RETAIN, { applyToUpdateReplaceP
14375Tags.of(backend.stack).add("gen1-migrated-app", "true");
14476\`\`\`
14577
146- 2 .b) Deploy sandbox using the below command or trigger a CI/CD build via hosting by committing this file to your Git repository
78+ 1 .b) Deploy sandbox using the below command or trigger a CI/CD build via hosting by committing this file to your Git repository
14779\`\`\`
14880npx ampx sandbox
14981\`\`\`
0 commit comments