This is the AWS CDK v2 Developer Guide. The older CDK v1 entered maintenance on June 1, 2022 and ended support on June 1, 2023.
cdk migrate
Migrate deployed AWS resources, AWS CloudFormation stacks, and CloudFormation templates into a new AWS CDK project.
This command creates a new CDK app that includes a single stack that is named with the value you provide using
--stack-name
. You can configure the migration source using --from-scan
,
--from-stack
, or --from-path
.
For more information on using cdk migrate
, see Migrate existing resources and AWS CloudFormation templates to the AWS CDK.
Note
The cdk migrate
command is experimental and may have breaking changes in the future.
Usage
$
cdk migrate
<options>
Options
For a list of global options that work with all CDK CLI commands, see Global options.
Required options
--stack-name
STRING
-
The name of the AWS CloudFormation stack that will be created within the CDK app after migrating.
Required: Yes
Conditional options
--from-path
PATH
-
The path to the AWS CloudFormation template to migrate. Provide this option to specify a local template.
Required: Conditional. Required if migrating from a local AWS CloudFormation template.
--from-scan
STRING
-
When migrating deployed resources from an AWS environment, use this option to specify whether a new scan should be started or if the AWS CDK CLI should use the last successful scan.
Required: Conditional. Required when migrating from deployed AWS resources.
Accepted values:
most-recent
,new
--from-stack
BOOLEAN
-
Provide this option to migrate from a deployed AWS CloudFormation stack. Use
--stack-name
to specify the name of the deployed AWS CloudFormation stack.Required: Conditional. Required if migrating from a deployed AWS CloudFormation stack.
Optional options
--account
STRING
-
The account to retrieve the AWS CloudFormation stack template from.
Required: No
Default: The AWS CDK CLI obtains account information from default sources.
--compress
BOOLEAN
-
Provide this option to compress the generated CDK project into a ZIP file.
Required: No
--filter
ARRAY
-
Use when migrating deployed resources from an AWS account and AWS Region. This option specifies a filter to determine which deployed resources to migrate.
This option accepts an array of key-value pairs, where key represents the filter type and value represents the value to filter.
The following are accepted keys:
-
resource-identifier
– An identifier for the resource. Value can be the resource logical or physical ID. For example,resource-identifier="ClusterName"
. -
resource-type-prefix
– The AWS CloudFormation resource type prefix. For example, specifyresource-type-prefix="AWS::DynamoDB::"
to filter all Amazon DynamoDB resources. -
tag-key
– The key of a resource tag. For example,tag-key="myTagKey"
. -
tag-value
– The value of a resource tag. For example,tag-value="myTagValue"
.
Provide multiple key-value pairs for
AND
conditional logic. The following example filters for any DynamoDB resource that is tagged withmyTagKey
as the tag key:--filter resource-type-prefix="AWS::DynamoDB::", tag-key="myTagKey"
.Provide the
--filter
option multiple times in a single command forOR
conditional logic. The following example filters for any resource that is a DynamoDB resource or is tagged withmyTagKey
as the tag key:--filter resource-type-prefix="AWS::DynamoDB::" --filter tag-key="myTagKey"
.Required: No
-
--help, -h
BOOLEAN
-
Show command reference information for the
cdk migrate
command. --language
STRING
-
The programming language to use for the CDK project created during migration.
Required: No
Valid values:
typescript
,python
,java
,csharp
,go
.Default:
typescript
--output-path
PATH
-
The output path for the migrated CDK project.
Required: No
Default: By default, the AWS CDK CLI will use your current working directory.
--region
STRING
-
The AWS Region to retrieve the AWS CloudFormation stack template from.
Required: No
Default: The AWS CDK CLI obtains AWS Region information from default sources.
Examples
Simple example of migrating from a CloudFormation stack
Migrate from a deployed CloudFormation stack in a specific AWS environment using --from-stack
. Provide
--stack-name
to name your new CDK stack. The following is an example that migrates
myCloudFormationStack
to a new CDK app that is using TypeScript:
$
cdk migrate --language typescript --from-stack --stack-name 'myCloudFormationStack'
Simple example of migrating from a local CloudFormation template
Migrate from a local JSON or YAML CloudFormation template using --from-path
. Provide
--stack-name
to name your new CDK stack. The following is an example that creates a new CDK
app in TypeScript that includes a myCloudFormationStack
stack from a local
template.json
file:
$
cdk migrate --stack-name "myCloudFormationStack" --language typescript --from-path "./template.json"
Simple example of migrating from deployed AWS resources
Migrate deployed AWS resources from a specific AWS environment that are not associated with a CloudFormation stack
using --from-scan
. The CDK CLI utilizes the IaC generator service to scan for
resources and generate a template. Then, the CDK CLI references the template to create the new CDK app.
The following is an example that creates a new CDK app in TypeScript with a new
myCloudFormationStack
stack containing migrated AWS resources:
$
cdk migrate --language typescript --from-scan --stack-name "myCloudFormationStack"