Skip to content

Comments

feat: auth and storage refactor#14304

Merged
kaizencc merged 5 commits intogen2-migrationfrom
iankhou-gen2-migration-refactor
Oct 30, 2025
Merged

feat: auth and storage refactor#14304
kaizencc merged 5 commits intogen2-migrationfrom
iankhou-gen2-migration-refactor

Conversation

@iankhou
Copy link
Contributor

@iankhou iankhou commented Oct 28, 2025

Description of changes

Moved over and modified code from https://github.com/aws-amplify/amplify-cli/tree/migrations/packages/amplify-migration/src/commands/gen2/execute.

Auth and Storage.

Added an assessment state that displays resources available to migrate
Screenshot 2025-10-28 at 16 14 40

Added interactivity to allow migration per category.

Description of how you validated changes

Manual testing and deployment. Unit tests copied over.

Steps:

  1. Deploy a Todo application using Gen1 - env: dev, contains Api, Auth, Storage, Hosting
  2. Add a new env: migrate, deploy this
  3. Followed instructions at https://add-gen1-gen2-migrations.d1j0to8e01vtig.amplifyapp.com/react/start/migrate-to-gen2/#data until Executing migration (stop BEFORE this step).
  4. Run command like amplify-dev gen2-migration refactor --from amplify-amplifytestapp2-migrate-3e996 --to amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d --debug (amplify-dev) must be linked correctly).
  5. Validate that stateful resources were moved, by inspecting the Gen2 stack for the Auth UserPool and the S3 Bucket from the original Gen1 stack. Validate that the resources are not in the Gen1 stack.
  6. Follow generated post-migration steps. Uncomment the s3.bucketName or the deployment will create a new bucket (we do not want this).
  7. Pushing the change in step 6 will create a deployment if you are linked up via GitHub deployment. Otherwise, perform a manual deployment. See logs below.

Added debug logging:

/Volumes/workplace/amplify-cli-2/.bin/amplify-dev gen2-migration refactor --from amplify-amplifytestapp2-migrate-3e996 --to amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d --debug
Validating
🔍 Validating refactor parameters and prerequisites...
✅ Parameters validated: from=amplify-amplifytestapp2-migrate-3e996, to=amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d
✅ Gen1 metadata found
✅ AWS credentials validated
✅ ✅ Validation completed successfully
Executing
🔄 Starting Amplify Gen2 migration refactor execution...
we are in DEBUG mode
Moving resources from Gen1 stack: amplify-amplifytestapp2-migrate-3e996
To Gen2 stack: amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d
ℹ️  Using default migration strategy

🔍 Assessing available resources for migration...

📊 Migration Assessment Results:

🔹 AUTH Category:
   • Resources to migrate: 5
   • Resource types: AWS::Cognito::UserPool, AWS::Cognito::UserPoolClient, AWS::Cognito::IdentityPool, AWS::Cognito::IdentityPoolRoleAttachment
   • Source stack: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-amplifytestapp2-migrate-3e996-authamplifytestapp228d22080-WKTPVT2X7RNJ/db3f1620-b430-11f0-bf91-0e76718867ed

🔹 STORAGE Category:
   • Resources to migrate: 1
   • Resource types: AWS::S3::Bucket
   • Source stack: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-amplifytestapp2-migrate-3e996-storages3e1e96d81-1NQWM7F3SL9FF/d04ea410-b430-11f0-8adb-0affd646e8eb

✔ Select migration approach: · Migrate all categories
✅ Selected all categories: auth, storage
🔧 Executing CloudFormation stack refactor...
📋 Selected categories: auth, storage
[DEBUG] generateGen1PreProcessTemplate: Starting Gen1 pre-process template generation
[DEBUG] Gen1 Stack ID: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-amplifytestapp2-migrate-3e996-authamplifytestapp228d22080-WKTPVT2X7RNJ/db3f1620-b430-11f0-bf91-0e76718867ed
[DEBUG] Gen1 Stack Parameters count: 35
[DEBUG] Gen1 Stack Parameters: [
  {
    "ParameterKey": "authRoleArn",
    "ParameterValue": "arn:aws:iam::229816860325:role/amplify-amplifytestapp2-migrate-3e996-authRole"
  },
  {
    "ParameterKey": "autoVerifiedAttributes",
    "ParameterValue": "email"
  },
  {
    "ParameterKey": "allowUnauthenticatedIdentities",
    "ParameterValue": "true"
  },
  {
    "ParameterKey": "smsVerificationMessage",
    "ParameterValue": "Your verification code is {####}"
  },
  {
    "ParameterKey": "userpoolClientReadAttributes",
    "ParameterValue": "email"
  },
  {
    "ParameterKey": "breakCircularDependency",
    "ParameterValue": "true"
  },
  {
    "ParameterKey": "mfaTypes",
    "ParameterValue": "SMS Text Message"
  },
  {
    "ParameterKey": "emailVerificationSubject",
    "ParameterValue": "Your verification code"
  },
  {
    "ParameterKey": "sharedId",
    "ParameterValue": "28d22080"
  },
  {
    "ParameterKey": "useDefault",
    "ParameterValue": "default"
  },
  {
    "ParameterKey": "userpoolClientGenerateSecret",
    "ParameterValue": "false"
  },
  {
    "ParameterKey": "mfaConfiguration",
    "ParameterValue": "OFF"
  },
  {
    "ParameterKey": "identityPoolName",
    "ParameterValue": "amplifytestapp228d22080_identitypool_28d22080"
  },
  {
    "ParameterKey": "userPoolGroupList",
    "ParameterValue": ""
  },
  {
    "ParameterKey": "authSelections",
    "ParameterValue": "identityPoolAndUserPool"
  },
  {
    "ParameterKey": "resourceNameTruncated",
    "ParameterValue": "amplif28d22080"
  },
  {
    "ParameterKey": "smsAuthenticationMessage",
    "ParameterValue": "Your authentication code is {####}"
  },
  {
    "ParameterKey": "passwordPolicyMinLength",
    "ParameterValue": "8"
  },
  {
    "ParameterKey": "userPoolName",
    "ParameterValue": "amplifytestapp228d22080_userpool_28d22080"
  },
  {
    "ParameterKey": "userpoolClientWriteAttributes",
    "ParameterValue": "email"
  },
  {
    "ParameterKey": "dependsOn",
    "ParameterValue": ""
  },
  {
    "ParameterKey": "useEnabledMfas",
    "ParameterValue": "true"
  },
  {
    "ParameterKey": "usernameCaseSensitive",
    "ParameterValue": "false"
  },
  {
    "ParameterKey": "resourceName",
    "ParameterValue": "amplifytestapp228d22080"
  },
  {
    "ParameterKey": "env",
    "ParameterValue": "migrate"
  },
  {
    "ParameterKey": "serviceName",
    "ParameterValue": "Cognito"
  },
  {
    "ParameterKey": "emailVerificationMessage",
    "ParameterValue": "Your verification code is {####}"
  },
  {
    "ParameterKey": "userpoolClientRefreshTokenValidity",
    "ParameterValue": "30"
  },
  {
    "ParameterKey": "userpoolClientSetAttributes",
    "ParameterValue": "false"
  },
  {
    "ParameterKey": "unauthRoleArn",
    "ParameterValue": "arn:aws:iam::229816860325:role/amplify-amplifytestapp2-migrate-3e996-unauthRole"
  },
  {
    "ParameterKey": "requiredAttributes",
    "ParameterValue": "email"
  },
  {
    "ParameterKey": "passwordPolicyCharacters",
    "ParameterValue": ""
  },
  {
    "ParameterKey": "aliasAttributes",
    "ParameterValue": ""
  },
  {
    "ParameterKey": "userpoolClientLambdaRole",
    "ParameterValue": "amplif28d22080_userpoolclient_lambda_role"
  },
  {
    "ParameterKey": "defaultPasswordPolicy",
    "ParameterValue": "false"
  }
]
[DEBUG] Gen1 Stack Outputs count: 7
[DEBUG] Gen1 Stack Outputs: [
  {
    "OutputKey": "UserPoolId",
    "OutputValue": "us-east-1_zzZYrQ1P4",
    "Description": "Id for the user pool"
  },
  {
    "OutputKey": "AppClientIDWeb",
    "OutputValue": "qh0a6rj5fv3pj0ljam1dhj744",
    "Description": "The user pool app client id for web"
  },
  {
    "OutputKey": "AppClientID",
    "OutputValue": "5fhpfhakofjngfbjp3d2g6tfso",
    "Description": "The user pool app client id"
  },
  {
    "OutputKey": "IdentityPoolId",
    "OutputValue": "us-east-1:e8a3fb57-62b2-4141-b7d1-46c39d36288e",
    "Description": "Id for the identity pool"
  },
  {
    "OutputKey": "UserPoolArn",
    "OutputValue": "arn:aws:cognito-idp:us-east-1:229816860325:userpool/us-east-1_zzZYrQ1P4",
    "Description": "Arn for the user pool"
  },
  {
    "OutputKey": "IdentityPoolName",
    "OutputValue": "amplifytestapp228d22080_identitypool_28d22080__migrate"
  },
  {
    "OutputKey": "UserPoolName",
    "OutputValue": "amplifytestapp228d22080_userpool_28d22080"
  }
]
[DEBUG] Gen1 Template Resources count: 6
[DEBUG] Gen1 Resources to move: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Gen1 Resources to move count: 5
[DEBUG] Gen1 Resources to move details:
[DEBUG]   - UserPool: Type=AWS::Cognito::UserPool
[DEBUG]   - UserPoolClientWeb: Type=AWS::Cognito::UserPoolClient
[DEBUG]     DependsOn: ["UserPool"]
[DEBUG]   - UserPoolClient: Type=AWS::Cognito::UserPoolClient
[DEBUG]     DependsOn: ["UserPool"]
[DEBUG]   - IdentityPool: Type=AWS::Cognito::IdentityPool
[DEBUG]   - IdentityPoolRoleMap: Type=AWS::Cognito::IdentityPoolRoleAttachment
[DEBUG]     DependsOn: ["IdentityPool"]
[DEBUG] Resolving Gen1 parameters...
[DEBUG] Describing Gen1 stack resources...
[DEBUG] Gen1 Stack Resources count: 6
[DEBUG] Resolving Gen1 outputs...
[DEBUG] Resolving Gen1 dependencies...
[DEBUG] Resolving Gen1 conditions...
✔ Updated Gen 1 auth stack successfully
[DEBUG] generateGen2ResourceRemovalTemplate: Starting Gen2 resource removal template generation
[DEBUG] Gen2 Stack ID: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d-auth179371D7-1GVLOXFSIJNXE/31305490-b436-11f0-a383-0afffdf0f7eb
[DEBUG] Gen2 Stack Parameters count: 0
[DEBUG] Gen2 Stack Outputs count: 5
[DEBUG] Gen2 Stack Outputs: [
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthIdentityPool95B33077Ref",
    "OutputValue": "us-east-1:4a9a8b06-97f1-4acb-ab32-751657de1d3e"
  },
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthunauthenticatedUserRoleDEA98AC5Ref",
    "OutputValue": "amplify-dzb1rpv3p7ih3-mig-amplifyAuthunauthenticate-z4cuDNUhipwY"
  },
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthUserPoolAppClientA73EE204Ref",
    "OutputValue": "34r69s549qc5qjjj2ad9anmkun"
  },
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthauthenticatedUserRole9270AF3ARef",
    "OutputValue": "amplify-dzb1rpv3p7ih3-mig-amplifyAuthauthenticatedU-F2sL9k290chQ"
  },
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthUserPool4CAAA23ERef",
    "OutputValue": "us-east-1_t4c5zO1ID"
  }
]
[DEBUG] Gen2 Template Resources count: 8
[DEBUG] Gen2 Resources to remove: [
  'amplifyAuthUserPool4BA7F805',
  'amplifyAuthUserPoolNativeAppClient79534448',
  'amplifyAuthUserPoolAppClient2626C6F8',
  'amplifyAuthIdentityPool3FDE84CC',
  'amplifyAuthIdentityPoolRoleAttachment045F17C8'
]
[DEBUG] Gen2 Resources to remove count: 5
[DEBUG] Gen2 Resources to remove details:
[DEBUG]   - amplifyAuthUserPool4BA7F805: Type=AWS::Cognito::UserPool
[DEBUG]   - amplifyAuthUserPoolNativeAppClient79534448: Type=AWS::Cognito::UserPoolClient
[DEBUG]   - amplifyAuthUserPoolAppClient2626C6F8: Type=AWS::Cognito::UserPoolClient
[DEBUG]   - amplifyAuthIdentityPool3FDE84CC: Type=AWS::Cognito::IdentityPool
[DEBUG]   - amplifyAuthIdentityPoolRoleAttachment045F17C8: Type=AWS::Cognito::IdentityPoolRoleAttachment
[DEBUG]     DependsOn: ["amplifyAuthIdentityPool3FDE84CC","amplifyAuthUserPoolAppClient2626C6F8"]
[DEBUG] Removing Gen2 resources from Gen2 stack...
[DEBUG] removeGen2ResourcesFromGen2Stack: Removing Gen2 resources from Gen2 stack
[DEBUG] Resources to remove: [
  'amplifyAuthUserPool4BA7F805',
  'amplifyAuthUserPoolNativeAppClient79534448',
  'amplifyAuthUserPoolAppClient2626C6F8',
  'amplifyAuthIdentityPool3FDE84CC',
  'amplifyAuthIdentityPoolRoleAttachment045F17C8'
]
[DEBUG] Stack outputs count: 5
[DEBUG] Describing Gen2 stack resources...
[DEBUG] Gen2 Stack Resources count: 8
[DEBUG] Resolving Gen2 dependencies...
[DEBUG] Resolving Gen2 output references...
[DEBUG] Deleting resources from template...
[DEBUG] Deleting resource: amplifyAuthUserPool4BA7F805
[DEBUG] Deleting resource: amplifyAuthUserPoolNativeAppClient79534448
[DEBUG] Deleting resource: amplifyAuthUserPoolAppClient2626C6F8
[DEBUG] Deleting resource: amplifyAuthIdentityPool3FDE84CC
[DEBUG] Deleting resource: amplifyAuthIdentityPoolRoleAttachment045F17C8
[DEBUG] Gen2 template resources after removal: 3
✔ Updated Gen 2 auth stack successfully
[DEBUG] generateRefactorTemplates: Starting refactor template generation
[DEBUG] Gen1 resources to move: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Gen2 resources to remove: [
  'amplifyAuthUserPool4BA7F805',
  'amplifyAuthUserPoolNativeAppClient79534448',
  'amplifyAuthUserPoolAppClient2626C6F8',
  'amplifyAuthIdentityPool3FDE84CC',
  'amplifyAuthIdentityPoolRoleAttachment045F17C8'
]
[DEBUG] Gen1 logical resource IDs: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Building resource mapping...
[DEBUG] buildGen1ToGen2ResourceLogicalIdMapping: Building resource mapping
[DEBUG] Gen1 resources: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Gen2 resources: [
  'amplifyAuthUserPool4BA7F805',
  'amplifyAuthUserPoolNativeAppClient79534448',
  'amplifyAuthUserPoolAppClient2626C6F8',
  'amplifyAuthIdentityPool3FDE84CC',
  'amplifyAuthIdentityPoolRoleAttachment045F17C8'
]
[DEBUG] Processing Gen1 resource: UserPool (Type: AWS::Cognito::UserPool)
[DEBUG] Checking Gen2 resource: amplifyAuthUserPool4BA7F805 (Type: AWS::Cognito::UserPool)
[DEBUG] Mapping found: UserPool -> amplifyAuthUserPool4BA7F805
[DEBUG] Processing Gen1 resource: UserPoolClientWeb (Type: AWS::Cognito::UserPoolClient)
[DEBUG] Checking Gen2 resource: amplifyAuthUserPoolNativeAppClient79534448 (Type: AWS::Cognito::UserPoolClient)
[DEBUG] Checking Gen2 resource: amplifyAuthUserPoolAppClient2626C6F8 (Type: AWS::Cognito::UserPoolClient)
[DEBUG] Mapping found: UserPoolClientWeb -> amplifyAuthUserPoolAppClient2626C6F8
[DEBUG] Processing Gen1 resource: UserPoolClient (Type: AWS::Cognito::UserPoolClient)
[DEBUG] Checking Gen2 resource: amplifyAuthUserPoolNativeAppClient79534448 (Type: AWS::Cognito::UserPoolClient)
[DEBUG] Mapping found: UserPoolClient -> amplifyAuthUserPoolNativeAppClient79534448
[DEBUG] Processing Gen1 resource: IdentityPool (Type: AWS::Cognito::IdentityPool)
[DEBUG] Checking Gen2 resource: amplifyAuthIdentityPool3FDE84CC (Type: AWS::Cognito::IdentityPool)
[DEBUG] Mapping found: IdentityPool -> amplifyAuthIdentityPool3FDE84CC
[DEBUG] Processing Gen1 resource: IdentityPoolRoleMap (Type: AWS::Cognito::IdentityPoolRoleAttachment)
[DEBUG] Checking Gen2 resource: amplifyAuthIdentityPoolRoleAttachment045F17C8 (Type: AWS::Cognito::IdentityPoolRoleAttachment)
[DEBUG] Mapping found: IdentityPoolRoleMap -> amplifyAuthIdentityPoolRoleAttachment045F17C8
[DEBUG] Final resource mapping: [
  [ 'UserPool', 'amplifyAuthUserPool4BA7F805' ],
  [ 'UserPoolClientWeb', 'amplifyAuthUserPoolAppClient2626C6F8' ],
  [ 'UserPoolClient', 'amplifyAuthUserPoolNativeAppClient79534448' ],
  [ 'IdentityPool', 'amplifyAuthIdentityPool3FDE84CC' ],
  [
    'IdentityPoolRoleMap',
    'amplifyAuthIdentityPoolRoleAttachment045F17C8'
  ]
]
[DEBUG] Un-mapped Gen1 resources: []
[DEBUG] Un-mapped Gen2 resources: []
[DEBUG] Cloning templates...
[DEBUG] Cloned Gen1 template resources: 6
[DEBUG] Cloned Gen2 template resources: 3
[DEBUG] Adding Gen1 resources to Gen2 stack...
[DEBUG] addGen1ResourcesToGen2Stack: Adding Gen1 resources to Gen2 stack
[DEBUG] Resources to add: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Resource mapping: [
  [ 'UserPool', 'amplifyAuthUserPool4BA7F805' ],
  [ 'UserPoolClientWeb', 'amplifyAuthUserPoolAppClient2626C6F8' ],
  [ 'UserPoolClient', 'amplifyAuthUserPoolNativeAppClient79534448' ],
  [ 'IdentityPool', 'amplifyAuthIdentityPool3FDE84CC' ],
  [
    'IdentityPoolRoleMap',
    'amplifyAuthIdentityPoolRoleAttachment045F17C8'
  ]
]
[DEBUG] Adding resource: UserPool -> amplifyAuthUserPool4BA7F805
[DEBUG] No dependencies for resource: amplifyAuthUserPool4BA7F805
[DEBUG] Adding resource: UserPoolClientWeb -> amplifyAuthUserPoolAppClient2626C6F8
[DEBUG] Original dependencies for amplifyAuthUserPoolAppClient2626C6F8: [ 'UserPool' ]
[DEBUG] Mapping dependency: UserPool -> amplifyAuthUserPool4BA7F805
[DEBUG] Updated dependencies for amplifyAuthUserPoolAppClient2626C6F8: [ 'amplifyAuthUserPool4BA7F805' ]
[DEBUG] Adding resource: UserPoolClient -> amplifyAuthUserPoolNativeAppClient79534448
[DEBUG] Original dependencies for amplifyAuthUserPoolNativeAppClient79534448: [ 'UserPool' ]
[DEBUG] Mapping dependency: UserPool -> amplifyAuthUserPool4BA7F805
[DEBUG] Updated dependencies for amplifyAuthUserPoolNativeAppClient79534448: [ 'amplifyAuthUserPool4BA7F805' ]
[DEBUG] Adding resource: IdentityPool -> amplifyAuthIdentityPool3FDE84CC
[DEBUG] No dependencies for resource: amplifyAuthIdentityPool3FDE84CC
[DEBUG] Adding resource: IdentityPoolRoleMap -> amplifyAuthIdentityPoolRoleAttachment045F17C8
[DEBUG] Original dependencies for amplifyAuthIdentityPoolRoleAttachment045F17C8: [ 'IdentityPool' ]
[DEBUG] Mapping dependency: IdentityPool -> amplifyAuthIdentityPool3FDE84CC
[DEBUG] Updated dependencies for amplifyAuthIdentityPoolRoleAttachment045F17C8: [ 'amplifyAuthIdentityPool3FDE84CC' ]
[DEBUG] Gen2 template resources after adding Gen1 resources: 8
[DEBUG] Removing Gen1 resources from Gen1 stack...
[DEBUG] removeGen1ResourcesFromGen1Stack: Removing resources from Gen1 stack
[DEBUG] Resources to remove: [
  'UserPool',
  'UserPoolClientWeb',
  'UserPoolClient',
  'IdentityPool',
  'IdentityPoolRoleMap'
]
[DEBUG] Removing resource: UserPool
[DEBUG] Removing resource: UserPoolClientWeb
[DEBUG] Removing resource: UserPoolClient
[DEBUG] Removing resource: IdentityPool
[DEBUG] Removing resource: IdentityPoolRoleMap
[DEBUG] Gen1 template resources remaining: 1
[DEBUG] Refactor templates generated successfully
[DEBUG] Source template resources: 1
[DEBUG] Destination template resources: 8
✔ Moved auth resources from Gen 1 to Gen 2 stack successfully
[DEBUG] generateGen1PreProcessTemplate: Starting Gen1 pre-process template generation
[DEBUG] Gen1 Stack ID: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-amplifytestapp2-migrate-3e996-storages3e1e96d81-1NQWM7F3SL9FF/d04ea410-b430-11f0-8adb-0affd646e8eb
[DEBUG] Gen1 Stack Parameters count: 21
[DEBUG] Gen1 Stack Parameters: [
  {
    "ParameterKey": "s3PermissionsGuestPublic",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:DeleteObject"
  },
  {
    "ParameterKey": "bucketName",
    "ParameterValue": "amplifytestapp255a6f9a935434691b97e9f2acb5ff938"
  },
  {
    "ParameterKey": "s3PublicPolicy",
    "ParameterValue": "Public_policy_e1e96d81"
  },
  {
    "ParameterKey": "AuthenticatedAllowList",
    "ParameterValue": "ALLOW"
  },
  {
    "ParameterKey": "unauthRoleName",
    "ParameterValue": "amplify-amplifytestapp2-migrate-3e996-unauthRole"
  },
  {
    "ParameterKey": "s3PrivatePolicy",
    "ParameterValue": "Private_policy_e1e96d81"
  },
  {
    "ParameterKey": "selectedGuestPermissions",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:ListBucket,s3:DeleteObject"
  },
  {
    "ParameterKey": "s3PermissionsAuthenticatedPublic",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:DeleteObject"
  },
  {
    "ParameterKey": "s3PermissionsAuthenticatedPrivate",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:DeleteObject"
  },
  {
    "ParameterKey": "s3PermissionsAuthenticatedUploads",
    "ParameterValue": "s3:PutObject"
  },
  {
    "ParameterKey": "s3UploadsPolicy",
    "ParameterValue": "Uploads_policy_e1e96d81"
  },
  {
    "ParameterKey": "env",
    "ParameterValue": "migrate"
  },
  {
    "ParameterKey": "unauthPolicyName",
    "ParameterValue": "s3_amplify_e1e96d81"
  },
  {
    "ParameterKey": "authRoleName",
    "ParameterValue": "amplify-amplifytestapp2-migrate-3e996-authRole"
  },
  {
    "ParameterKey": "GuestAllowList",
    "ParameterValue": "ALLOW"
  },
  {
    "ParameterKey": "authPolicyName",
    "ParameterValue": "s3_amplify_e1e96d81"
  },
  {
    "ParameterKey": "s3ProtectedPolicy",
    "ParameterValue": "Protected_policy_e1e96d81"
  },
  {
    "ParameterKey": "s3PermissionsAuthenticatedProtected",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:DeleteObject"
  },
  {
    "ParameterKey": "s3PermissionsGuestUploads",
    "ParameterValue": "s3:PutObject"
  },
  {
    "ParameterKey": "s3ReadPolicy",
    "ParameterValue": "read_policy_e1e96d81"
  },
  {
    "ParameterKey": "selectedAuthenticatedPermissions",
    "ParameterValue": "s3:PutObject,s3:GetObject,s3:ListBucket,s3:DeleteObject"
  }
]
[DEBUG] Gen1 Stack Outputs count: 2
[DEBUG] Gen1 Stack Outputs: [
  {
    "OutputKey": "BucketName",
    "OutputValue": "amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996-migrate",
    "Description": "Bucket name for the S3 bucket"
  },
  {
    "OutputKey": "Region",
    "OutputValue": "us-east-1"
  }
]
[DEBUG] Gen1 Template Resources count: 9
[DEBUG] Gen1 Resources to move: [ 'S3Bucket' ]
[DEBUG] Gen1 Resources to move count: 1
[DEBUG] Gen1 Resources to move details:
[DEBUG]   - S3Bucket: Type=AWS::S3::Bucket
[DEBUG] Resolving Gen1 parameters...
[DEBUG] Describing Gen1 stack resources...
[DEBUG] Gen1 Stack Resources count: 9
[DEBUG] Resolving Gen1 outputs...
[DEBUG] Resolving Gen1 dependencies...
[DEBUG] Resolving Gen1 conditions...
✔ Updated Gen 1 storage stack successfully
[DEBUG] generateGen2ResourceRemovalTemplate: Starting Gen2 resource removal template generation
[DEBUG] Gen2 Stack ID: arn:aws:cloudformation:us-east-1:229816860325:stack/amplify-dzb1rpv3p7ih3-migrate-branch-caf557ea2d-storage0EC3F24A-E4M3UI9LYVQ1/4de67d30-b436-11f0-9231-12f02aa4c4e1
[DEBUG] Gen2 Stack Parameters count: 2
[DEBUG] Gen2 Stack Parameters: [
  {
    "ParameterKey": "referencetoamplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthNestedStackauthNestedStackResourceBE21D2E7Outputsamplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthunauthenticatedUserRoleDEA98AC5Ref",
    "ParameterValue": "amplify-dzb1rpv3p7ih3-mig-amplifyAuthunauthenticate-z4cuDNUhipwY"
  },
  {
    "ParameterKey": "referencetoamplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthNestedStackauthNestedStackResourceBE21D2E7Outputsamplifydzb1rpv3p7ih3migratebranchcaf557ea2dauthamplifyAuthauthenticatedUserRole9270AF3ARef",
    "ParameterValue": "amplify-dzb1rpv3p7ih3-mig-amplifyAuthauthenticatedU-F2sL9k290chQ"
  }
]
[DEBUG] Gen2 Stack Outputs count: 1
[DEBUG] Gen2 Stack Outputs: [
  {
    "OutputKey": "amplifydzb1rpv3p7ih3migratebranchcaf557ea2dstorageamplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket2A08A473Ref",
    "OutputValue": "amplify-dzb1rpv3p7ih3-mig-amplifytestapp255a6f9a93-nk7m5nkerefg"
  }
]
[DEBUG] Gen2 Template Resources count: 9
[DEBUG] Gen2 Resources to remove: [
  'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
]
[DEBUG] Gen2 Resources to remove count: 1
[DEBUG] Gen2 Resources to remove details:
[DEBUG]   - amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE: Type=AWS::S3::Bucket
[DEBUG] Removing Gen2 resources from Gen2 stack...
[DEBUG] removeGen2ResourcesFromGen2Stack: Removing Gen2 resources from Gen2 stack
[DEBUG] Resources to remove: [
  'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
]
[DEBUG] Stack outputs count: 1
[DEBUG] Describing Gen2 stack resources...
[DEBUG] Gen2 Stack Resources count: 9
[DEBUG] Resolving Gen2 dependencies...
[DEBUG] Resolving Gen2 output references...
[DEBUG] Deleting resources from template...
[DEBUG] Deleting resource: amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE
[DEBUG] Gen2 template resources after removal: 8
✔ Updated Gen 2 storage stack successfully
[DEBUG] generateRefactorTemplates: Starting refactor template generation
[DEBUG] Gen1 resources to move: [ 'S3Bucket' ]
[DEBUG] Gen2 resources to remove: [
  'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
]
[DEBUG] Gen1 logical resource IDs: [ 'S3Bucket' ]
[DEBUG] Building resource mapping...
[DEBUG] buildGen1ToGen2ResourceLogicalIdMapping: Building resource mapping
[DEBUG] Gen1 resources: [ 'S3Bucket' ]
[DEBUG] Gen2 resources: [
  'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
]
[DEBUG] Processing Gen1 resource: S3Bucket (Type: AWS::S3::Bucket)
[DEBUG] Checking Gen2 resource: amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE (Type: AWS::S3::Bucket)
[DEBUG] Mapping found: S3Bucket -> amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE
[DEBUG] Final resource mapping: [
  [
    'S3Bucket',
    'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
  ]
]
[DEBUG] Un-mapped Gen1 resources: []
[DEBUG] Un-mapped Gen2 resources: []
[DEBUG] Cloning templates...
[DEBUG] Cloned Gen1 template resources: 9
[DEBUG] Cloned Gen2 template resources: 8
[DEBUG] Adding Gen1 resources to Gen2 stack...
[DEBUG] addGen1ResourcesToGen2Stack: Adding Gen1 resources to Gen2 stack
[DEBUG] Resources to add: [ 'S3Bucket' ]
[DEBUG] Resource mapping: [
  [
    'S3Bucket',
    'amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE'
  ]
]
[DEBUG] Adding resource: S3Bucket -> amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE
[DEBUG] No dependencies for resource: amplifytestapp255a6f9a935434691b97e9f2acb5ff9383e996migrateBucket00C475FE
[DEBUG] Gen2 template resources after adding Gen1 resources: 9
[DEBUG] Removing Gen1 resources from Gen1 stack...
[DEBUG] removeGen1ResourcesFromGen1Stack: Removing resources from Gen1 stack
[DEBUG] Resources to remove: [ 'S3Bucket' ]
[DEBUG] Removing resource: S3Bucket
[DEBUG] Gen1 template resources remaining: 8
[DEBUG] Refactor templates generated successfully
[DEBUG] Source template resources: 8
[DEBUG] Destination template resources: 9
✔ Moved storage resources from Gen 1 to Gen 2 stack successfully
✅ ✅ CloudFormation stack refactor completed successfully under .amplify/migration/templates directory.
Analytics: refactor command succeeded for env: migrate
✅ ✅ Gen2 migration refactor completed successfully!

Next steps:
1. Review the generated templates in .amplify/migration/templates/
7. Follow the instructions in the README files
8. Verify that resources have been moved correctly in the AWS Console
9. Test your application to ensure all functionality works as expected

For more information, visit: https://docs.amplify.aws/react/start/migrate-to-gen2/

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@iankhou iankhou requested a review from a team as a code owner October 28, 2025 20:15
@iankhou iankhou force-pushed the iankhou-gen2-migration-refactor branch 4 times, most recently from 192fe8e to c671368 Compare October 28, 2025 21:59
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structural questions. also, if you say you "modified code", where?

i assume the moved code was peer-reviewed at some point, so i wanna make sure any new code is peer-reviewed too

Mostly to get ore information for debugging. No functional changes.

const MIGRATION_DIR = '.amplify/migration';
const AMPLIFY_DIR = 'amplify';

export class AmplifyMigrationRefactorStep extends AmplifyMigrationStep {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you decide to move this away from src/commands/gen2-migration/refactor.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have kept the name, it there is so much accessory code that it made sense to organize it in its own directory. Using an index file is the usual convention, in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are test files included alongside source code? seems to me like convention in this repository is to include tests in the src/__tests__/ folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll move the tests there.

@iankhou iankhou force-pushed the iankhou-gen2-migration-refactor branch from 689e6d7 to 3b865d7 Compare October 30, 2025 18:09
Comment on lines +10 to +13
if (resource?.DependsOn) {
// Normalize DependsOn to array for processing
const deps = Array.isArray(resource.DependsOn) ? resource.DependsOn : [resource.DependsOn];
const depsInRefactor = deps.filter((dep: string) => resourcesToRefactor.includes(dep));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional change here. Normalize DependsOn, which can be either a string or an array of strings, to be an array.

@iankhou iankhou requested a review from kaizencc October 30, 2025 18:50
@kaizencc kaizencc merged commit 515d1dd into gen2-migration Oct 30, 2025
4 checks passed
@kaizencc kaizencc deleted the iankhou-gen2-migration-refactor branch October 30, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants