11import { AmplifyMigrationStep } from './_step' ;
22import { printer } from '@aws-amplify/amplify-prompts' ;
3+ import { AmplifyGen2MigrationValidations } from './_validations' ;
4+ import {
5+ CloudFormationClient ,
6+ CreateChangeSetCommand ,
7+ DescribeChangeSetCommand ,
8+ DeleteChangeSetCommand ,
9+ DescribeChangeSetOutput ,
10+ waitUntilChangeSetCreateComplete ,
11+ } from '@aws-sdk/client-cloudformation' ;
12+ import { stateManager } from '@aws-amplify/amplify-cli-core' ;
313
414export class AmplifyMigrationDecommissionStep extends AmplifyMigrationStep {
515 readonly command = 'decommission' ;
6- readonly describe = 'Decommission Gen1 resources' ;
16+ readonly describe = 'Decommission Gen1 resources after migration ' ;
717
818 public async validate ( ) : Promise < void > {
9- printer . warn ( 'Not implemented' ) ;
19+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20+ const validations = new AmplifyGen2MigrationValidations ( { } as any ) ;
21+ // eslint-disable-next-line spellcheck/spell-checker
22+ await validations . validateStatefulResources ( await this . createChangeSet ( ) ) ;
1023 }
1124
1225 public async execute ( ) : Promise < void > {
@@ -16,4 +29,44 @@ export class AmplifyMigrationDecommissionStep extends AmplifyMigrationStep {
1629 public async rollback ( ) : Promise < void > {
1730 printer . warn ( 'Not implemented' ) ;
1831 }
32+
33+ private async createChangeSet ( ) : Promise < DescribeChangeSetOutput > {
34+ const meta = stateManager . getMeta ( ) ;
35+ const stackName = meta . providers . awscloudformation . StackName ;
36+
37+ const cfn = new CloudFormationClient ( { } ) ;
38+ const changeSetName = `decommission-${ Date . now ( ) } ` ;
39+
40+ await cfn . send (
41+ new CreateChangeSetCommand ( {
42+ StackName : stackName ,
43+ ChangeSetName : changeSetName ,
44+ TemplateBody : JSON . stringify ( {
45+ Resources : {
46+ DummyResource : {
47+ Type : 'AWS::CloudFormation::WaitConditionHandle' ,
48+ } ,
49+ } ,
50+ } ) ,
51+ } ) ,
52+ ) ;
53+
54+ await waitUntilChangeSetCreateComplete ( { client : cfn , maxWaitTime : 120 } , { StackName : stackName , ChangeSetName : changeSetName } ) ;
55+
56+ const changeSet = await cfn . send (
57+ new DescribeChangeSetCommand ( {
58+ StackName : stackName ,
59+ ChangeSetName : changeSetName ,
60+ } ) ,
61+ ) ;
62+
63+ await cfn . send (
64+ new DeleteChangeSetCommand ( {
65+ StackName : stackName ,
66+ ChangeSetName : changeSetName ,
67+ } ) ,
68+ ) ;
69+
70+ return changeSet ;
71+ }
1972}
0 commit comments