From b2a69ec99cd8a97ce6b3fc17f96569435fda0974 Mon Sep 17 00:00:00 2001 From: Sai Ray Date: Wed, 2 Dec 2026 15:13:43 -0500 Subject: [PATCH 1/4] chore: midwork --- packages/aws-cdk/README.md | 2 ++ packages/aws-cdk/lib/cli/cdk-toolkit.ts | 14 +++++++++++++- packages/aws-cdk/lib/commands/migrate.ts | 5 ++++- packages/aws-cdk/test/cli/cdk-toolkit.test.ts | 4 ++++ packages/aws-cdk/test/commands/migrate.test.ts | 6 ++++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index e6871dfb3..545fdad36 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -1091,6 +1091,8 @@ The table remains available throughout the entire process with zero downtime. ⚠️**CAUTION**⚠️: CDK Migrate is currently experimental and may have breaking changes in the future. +The generated CDK code is based on the CloudFormation template or AWS resources you migrate. This code runs on your machine when you run `cdk synth` or `cdk deploy`. Review it before you run either command. + CDK Migrate generates a CDK app from deployed AWS resources using `--from-scan`, deployed AWS CloudFormation stacks using `--from-stack`, and local AWS CloudFormation templates using `--from-path`. To learn more about the CDK Migrate feature, see [Migrate to AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/migrate.html). For more information on `cdk migrate` command options, see [cdk migrate command reference](https://docs.aws.amazon.com/cdk/v2/guide/ref-cli-cdk-migrate.html). diff --git a/packages/aws-cdk/lib/cli/cdk-toolkit.ts b/packages/aws-cdk/lib/cli/cdk-toolkit.ts index 617bd050a..e9525be4f 100644 --- a/packages/aws-cdk/lib/cli/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cli/cdk-toolkit.ts @@ -1384,7 +1384,14 @@ export class CdkToolkit { } const stack = generateStack(generateTemplateOutput.migrateJson.templateBody, options.stackName, language); await this.ioHost.asIoHelper().defaults.info(chalk.green(' ⏳ Generating CDK app for %s...'), chalk.blue(options.stackName)); - await generateCdkApp(this.ioHost.asIoHelper(), options.stackName, stack!, language, options.outputPath, options.compress); + const generatedCodePath = await generateCdkApp( + this.ioHost.asIoHelper(), + options.stackName, + stack!, + language, + options.outputPath, + options.compress, + ); if (generateTemplateOutput) { writeMigrateJsonFile(options.outputPath, options.stackName, generateTemplateOutput.migrateJson); } @@ -1397,6 +1404,11 @@ export class CdkToolkit { generateTemplateOutput.resources!, ); } + await this.ioHost.asIoHelper().defaults.warn( + ' ⚠️ The generated CDK code is based on the CloudFormation template or AWS resources you migrated.\n' + + ' Review %s before running cdk synth or cdk deploy.', + generatedCodePath, + ); } catch (e) { await this.ioHost.asIoHelper().defaults.error(' ❌ Migrate failed for `%s`: %s', options.stackName, (e as Error).message); throw e; diff --git a/packages/aws-cdk/lib/commands/migrate.ts b/packages/aws-cdk/lib/commands/migrate.ts index de1fe4f38..cdfddee8f 100644 --- a/packages/aws-cdk/lib/commands/migrate.ts +++ b/packages/aws-cdk/lib/commands/migrate.ts @@ -37,6 +37,7 @@ const MIGRATE_SUPPORTED_LANGUAGES: readonly string[] = cdk_from_cfn.supported_la * @param stack - The yaml or json template for the stack * @param language - The language to generate the CDK app in * @param outputPath - The path at which to generate the CDK app + * @returns The path to the generated stack file, or to the zip file when `compress` is set */ export async function generateCdkApp( ioHelper: IoHelper, @@ -45,7 +46,7 @@ export async function generateCdkApp( language: string, outputPath?: string, compress?: boolean, -): Promise { +): Promise { const resolvedOutputPath = path.join(outputPath ?? process.cwd(), stackName); const formattedStackName = decamelize(stackName); @@ -91,7 +92,9 @@ export async function generateCdkApp( if (compress) { await zipDirectory(resolvedOutputPath, `${resolvedOutputPath}.zip`); fs.rmSync(resolvedOutputPath, { recursive: true, force: true }); + return `${resolvedOutputPath}.zip`; } + return stackFileName; } catch (error) { fs.rmSync(resolvedOutputPath, { recursive: true, force: true }); throw error; diff --git a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts index 08092cbe2..aa918f37e 100644 --- a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts @@ -2865,6 +2865,10 @@ describe('migrate', () => { expect(fs.pathExistsSync(path.join(workDir, 'SQSTypeScript', 'package.json'))).toBeTruthy(); expect(fs.pathExistsSync(path.join(workDir, 'SQSTypeScript', 'bin', 'sqs_type_script.ts'))).toBeTruthy(); expect(fs.pathExistsSync(path.join(workDir, 'SQSTypeScript', 'lib', 'sqs_type_script-stack.ts'))).toBeTruthy(); + expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ + level: 'warn', + message: expect.stringContaining(`Review ${path.join(workDir, 'SQSTypeScript', 'lib', 'sqs_type_script-stack.ts')} before running cdk synth or cdk deploy`), + })); }); cliTest('migrate succeeds for valid template from local path when language is provided', async (workDir) => { diff --git a/packages/aws-cdk/test/commands/migrate.test.ts b/packages/aws-cdk/test/commands/migrate.test.ts index bd04e82c8..9c13bc41f 100644 --- a/packages/aws-cdk/test/commands/migrate.test.ts +++ b/packages/aws-cdk/test/commands/migrate.test.ts @@ -255,7 +255,8 @@ describe('Migrate Function Tests', () => { cliTest('generateCdkApp generates the expected cdk app when called for typescript', async (workDir) => { const stack = generateStack(validTemplate, 'GoodTypeScript', 'typescript'); - await generateCdkApp(ioHelper, 'GoodTypeScript', stack, 'typescript', workDir); + const generatedCodePath = await generateCdkApp(ioHelper, 'GoodTypeScript', stack, 'typescript', workDir); + expect(generatedCodePath).toEqual(path.join(workDir, 'GoodTypeScript', 'lib', 'good_type_script-stack.ts')); // Packages exist in the correct spot expect(fs.pathExistsSync(path.join(workDir, 'GoodTypeScript', 'package.json'))).toBeTruthy(); @@ -402,7 +403,8 @@ describe('Migrate Function Tests', () => { cliTest('generatedCdkApp generates a zip file when --compress is used', async (workDir) => { const stack = generateStack(validTemplate, 'GoodTypeScript', 'typescript'); - await generateCdkApp(ioHelper, 'GoodTypeScript', stack, 'typescript', workDir, true); + const generatedCodePath = await generateCdkApp(ioHelper, 'GoodTypeScript', stack, 'typescript', workDir, true); + expect(generatedCodePath).toEqual(path.join(workDir, 'GoodTypeScript.zip')); // Packages not in outDir expect(fs.pathExistsSync(path.join(workDir, 'GoodTypeScript', 'package.json'))).toBeFalsy(); From 8dc908926f3a9baa776b3fa554df5592b688608f Mon Sep 17 00:00:00 2001 From: Sai Ray Date: Wed, 2 Dec 2026 15:41:32 -0500 Subject: [PATCH 2/4] chore: midwork --- packages/aws-cdk/lib/cli/cdk-toolkit.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/aws-cdk/lib/cli/cdk-toolkit.ts b/packages/aws-cdk/lib/cli/cdk-toolkit.ts index e9525be4f..13594a2b8 100644 --- a/packages/aws-cdk/lib/cli/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cli/cdk-toolkit.ts @@ -1405,8 +1405,7 @@ export class CdkToolkit { ); } await this.ioHost.asIoHelper().defaults.warn( - ' ⚠️ The generated CDK code is based on the CloudFormation template or AWS resources you migrated.\n' + - ' Review %s before running cdk synth or cdk deploy.', + ' ⚠️ The generated CDK code is based on the CloudFormation template or AWS resources you migrated. Review %s before running cdk synth or cdk deploy.', generatedCodePath, ); } catch (e) { From 45199fe5f1911ed06016c4269677fa73741693e8 Mon Sep 17 00:00:00 2001 From: Sai Ray Date: Wed, 2 Dec 2026 16:02:04 -0500 Subject: [PATCH 3/4] chore: midwork --- packages/aws-cdk/lib/cli/cdk-toolkit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk/lib/cli/cdk-toolkit.ts b/packages/aws-cdk/lib/cli/cdk-toolkit.ts index 13594a2b8..9f62e95e2 100644 --- a/packages/aws-cdk/lib/cli/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cli/cdk-toolkit.ts @@ -1405,7 +1405,7 @@ export class CdkToolkit { ); } await this.ioHost.asIoHelper().defaults.warn( - ' ⚠️ The generated CDK code is based on the CloudFormation template or AWS resources you migrated. Review %s before running cdk synth or cdk deploy.', + ` ⚠️ The generated CDK code is based on the CloudFormation template or AWS resources you migrated. Review %s before running ${chalk.blueBright('cdk synth')} or ${chalk.blueBright('cdk deploy')}.`, generatedCodePath, ); } catch (e) { From f07dfd487bfed36630ae2454e79f5882e8ebb4bd Mon Sep 17 00:00:00 2001 From: Sai Ray Date: Wed, 2 Dec 2026 16:56:01 -0500 Subject: [PATCH 4/4] chore: midwork --- packages/aws-cdk/test/cli/cdk-toolkit.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts index aa918f37e..b842beed3 100644 --- a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts @@ -72,6 +72,7 @@ import type { CloudFormationClientResolvedConfig, CreateChangeSetInput, CreateCh import { CreateChangeSetCommand, DeleteChangeSetCommand, DescribeChangeSetCommand, DescribeStacksCommand, ExecuteChangeSetCommand, GetTemplateCommand, StackStatus } from '@aws-sdk/client-cloudformation'; import { GetParameterCommand } from '@aws-sdk/client-ssm'; import type { AwsStub } from 'aws-sdk-client-mock'; +import chalk from 'chalk'; import * as fs from 'fs-extra'; import { type Template, type SdkProvider, ResourceImporter, StackAssembly, WorkGraphBuilder } from '../../lib/api'; import { mustMatch, selectExact, selectOnlySingle, selectWithUpstream } from '../../lib/api'; @@ -2867,7 +2868,7 @@ describe('migrate', () => { expect(fs.pathExistsSync(path.join(workDir, 'SQSTypeScript', 'lib', 'sqs_type_script-stack.ts'))).toBeTruthy(); expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'warn', - message: expect.stringContaining(`Review ${path.join(workDir, 'SQSTypeScript', 'lib', 'sqs_type_script-stack.ts')} before running cdk synth or cdk deploy`), + message: expect.stringContaining(`Review ${path.join(workDir, 'SQSTypeScript', 'lib', 'sqs_type_script-stack.ts')} before running ${chalk.blueBright('cdk synth')} or ${chalk.blueBright('cdk deploy')}`), })); });