Skip to content

Commit db051ea

Browse files
HBobertzHogan Bobertzcomcalvimadeline-k
authored
feat(cli): CDK Migrate CLI command (#27325)
* add CDK migrate readme * modifications to cdk migrate readme * some fixes to readme, still WIP * update readmea with more info * remove random whitespace * added more intro to the cdk migrate command * readme modifications * change some wording * remove description of flags * annotate code block with json * callout the L1s * updtae to readme * Update packages/aws-cdk/README.md Co-authored-by: Calvin Combs <[email protected]> * Update packages/aws-cdk/README.md Co-authored-by: Calvin Combs <[email protected]> * Update packages/aws-cdk/README.md Co-authored-by: Madeline Kusters <[email protected]> * update readme with comments * added a limitations table * update readme to have bullets this time * change * to - * more readme updates * more updates --------- Co-authored-by: Hogan Bobertz <[email protected]> Co-authored-by: Calvin Combs <[email protected]> Co-authored-by: Madeline Kusters <[email protected]>
1 parent 01b14da commit db051ea

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

packages/aws-cdk/README.md

+121
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The AWS CDK Toolkit provides the `cdk` command-line interface that can be used t
2020
| [`cdk diff`](#cdk-diff) | Diff stacks against current state |
2121
| [`cdk deploy`](#cdk-deploy) | Deploy a stack into an AWS account |
2222
| [`cdk import`](#cdk-import) | Import existing AWS resources into a CDK stack |
23+
| [`cdk migrate`](#cdk-migrate) | Convert an existing CFN template into a CDK Application |
2324
| [`cdk watch`](#cdk-watch) | Watches a CDK app for deployable and hotswappable changes |
2425
| [`cdk destroy`](#cdk-destroy) | Deletes a stack from an AWS account |
2526
| [`cdk bootstrap`](#cdk-bootstrap) | Deploy a toolkit stack to support deploying large stacks & artifacts |
@@ -560,6 +561,126 @@ This feature currently has the following limitations:
560561
bucket). Requires version 12 of the bootstrap stack, for the added
561562
IAM permissions to the `deploy-role`.
562563

564+
565+
### `cdk migrate`
566+
567+
⚠️**CAUTION**⚠️
568+
569+
CDK Migrate is currently experimental and may have breaking changes in the future.
570+
571+
CDK Migrate Generates a CDK application using an existing CloudFormation template in JSON or YAML format.
572+
Templates can be provided from either from a local file using `--from-path` or directly from a
573+
deployed CloudFormation stack with `--from-stack`. The generated CDK application will
574+
synthesize a CloudFormation template with identical resource configurations to the provided template.
575+
The generated application will be initialized in the current working directory with a single stack where
576+
the stack, app, and directory will all be named using the provided `--stack-name`. It will also
577+
be within a generated subdirectory in your current working directory unless `--output-path` is specified.
578+
If a directory already exists with the same name as `--stack-name`, it will be replaced with the new application.
579+
All CDK supported languages are supported, language choice can be specified with `--language`.
580+
581+
#### Generate a typescript application from a local template.json file
582+
583+
```console
584+
$ # template.json is a valid cloudformation template in the local directory
585+
$ cdk migrate --stack-name MyAwesomeApplication --language typescript --from-path MyTemplate.json
586+
```
587+
588+
This command will generate a new directory named `MyAwesomeApplication` within your current working directory, and
589+
then initialize a new CDK application within that directory which has the same resource configuration
590+
as the provided template.json
591+
592+
This results in a CDK application with the following structure, where the lib directory contains a stack definition
593+
with the same resource configuration as the provided template.json.
594+
595+
```console
596+
├── README.md
597+
├── bin
598+
│ └── my_awesome_application.ts
599+
├── cdk.json
600+
├── jest.config.js
601+
├── lib
602+
│ └── my_awesome_application-stack.ts
603+
├── package.json
604+
├── tsconfig.json
605+
```
606+
607+
#### Generate a python application from a deployed stack
608+
609+
If you already have a CloudFormation stack deployed in your account and would like to manage it with CDK, you can use the
610+
`--from-stack` option to generate the application. In this case the `--stack-name` must match the name of the deployed stack.
611+
612+
```console
613+
$ # generate a python application from MyDeployedStack in your account
614+
$ cdk migrate --stack-name MyDeployedStack --language python --from-stack
615+
```
616+
617+
This will generate a Python CDK application which will synthesize the same configuration of resources as the deployed stack.
618+
619+
#### **CDK Migrate Limitations**
620+
621+
- CDK Migrate does not currently support nested stacks, custom resources, or the `Fn::ForEach` intrinsic function.
622+
623+
- CDK Migrate will only generate L1 constructs and does not currently support any higher level abstractions.
624+
625+
- CDK Migrate successfully generating an application does *not* guarantee the application is immediately deployable.
626+
It simply generates a CDK application which will synthesize a template that has identical resource configurations
627+
to the provided template.
628+
629+
- CDK Migrate does not interact with the CloudFormation service to verify the template
630+
provided can deploy on its own. This means CDK Migrate will not verify that any resources in the provided
631+
template are already managed in other CloudFormation templates, nor will it verify that the resources in the provided
632+
template are available in the desired regions, which may impact ADC or Opt-In regions.
633+
634+
- If the provided template has parameters without default values, those will need to be provided
635+
before deploying the generated application.
636+
637+
In practice this is how CDK Migrate generated applications will operate in the following scenarios:
638+
639+
| Situation | Result |
640+
| ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
641+
| Provided template + stack-name is from a deployed stack in the account/region | The CDK application will deploy as a changeset to the existing stack |
642+
| Provided template has no overlap with resources already in the account/region | The CDK application will deploy a new stack successfully |
643+
| Provided template has overlap with Cloudformation managed resources already in the account/region | The CDK application will not be deployable unless those resources are removed |
644+
| Provided template has overlap with unmanaged resources already in the account/region | The CDK application will not be deployable until those resources are adopted with [`cdk import`](#cdk-import) |
645+
646+
647+
##### **The provided template is already deployed to CloudFormation in the account/region**
648+
649+
If the provided template came directly from a deployed CloudFormation stack, and that stack has not experienced any drift,
650+
then the generated application will be immediately deployable, and will not cause any changes to the deployed resources.
651+
Drift might occur if a resource in your template was modified outside of CloudFormation, namely via the AWS Console or AWS CLI.
652+
653+
##### **The provided template is not deployed to CloudFormation in the account/region, and there *is not* overlap with existing resources in the account/region**
654+
655+
If the provided template represents a set of resources that have no overlap with resources already deployed in the account/region,
656+
then the generated application will be immediately deployable. This could be because the stack has never been deployed, or
657+
the application was generated from a stack deployed in another account/region.
658+
659+
In practice this means for any resource in the provided template, for example,
660+
661+
```Json
662+
"S3Bucket": {
663+
"Type": "AWS::S3::Bucket",
664+
"Properties": {
665+
"BucketName": "MyBucket",
666+
"AccessControl": "PublicRead",
667+
},
668+
"DeletionPolicy": "Retain"
669+
}
670+
```
671+
672+
There must not exist a resource of that type with the same identifier in the desired region. In this example that identfier
673+
would be "MyBucket"
674+
675+
##### **The provided template is not deployed to CloudFormation in the account/region, and there *is* overlap with existing resources in the account/region**
676+
677+
If the provided template represents a set of resources that overlap with resources already deployed in the account/region,
678+
then the generated application will not be immediately deployable. If those overlapped resources are already managed by
679+
another CloudFormation stack in that account/region, then those resources will need to be manually removed from the provided
680+
template. Otherwise, if the overlapped resources are not managed by another CloudFormation stack, then first remove those
681+
resources from your CDK Application Stack, deploy the cdk application successfully, then re-add them and run `cdk import`
682+
to import them into your deployed stack.
683+
563684
### `cdk destroy`
564685

565686
Deletes a stack from it's environment. This will cause the resources in the stack to be destroyed (unless they were

0 commit comments

Comments
 (0)