-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): CDK Migrate CLI command #27325
Changes from 13 commits
5091192
ab21a14
9c9002c
659fb6f
db94dc7
f21ee4f
94d2f39
681b88d
50f4b6d
64623c4
d8052cf
c5c0d1a
81ed49f
a13630b
cb94039
06e0b88
ff41695
c884f58
9327161
7087358
8c8e37c
806d542
eb1c0e4
c02bb96
7af64c5
3104733
6cae5ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ The AWS CDK Toolkit provides the `cdk` command-line interface that can be used t | |||||||||
| [`cdk diff`](#cdk-diff) | Diff stacks against current state | | ||||||||||
| [`cdk deploy`](#cdk-deploy) | Deploy a stack into an AWS account | | ||||||||||
| [`cdk import`](#cdk-import) | Import existing AWS resources into a CDK stack | | ||||||||||
| [`cdk migrate`](#cdk-migrate) | Convert an existing CFN template into a CDK Application | | ||||||||||
| [`cdk watch`](#cdk-watch) | Watches a CDK app for deployable and hotswappable changes | | ||||||||||
| [`cdk destroy`](#cdk-destroy) | Deletes a stack from an AWS account | | ||||||||||
| [`cdk bootstrap`](#cdk-bootstrap) | Deploy a toolkit stack to support deploying large stacks & artifacts | | ||||||||||
|
@@ -560,6 +561,111 @@ This feature is currently in preview. Be aware of the following limitations: | |||||||||
in the right order. The CLI will not help you import dependent resources in the right | ||||||||||
order, the CloudFormation deployment will fail with unresolved references. | ||||||||||
|
||||||||||
|
||||||||||
### `cdk migrate` | ||||||||||
|
||||||||||
⚠️**CAUTION**⚠️ | ||||||||||
|
||||||||||
CDK migrate is currently experimental and may have breaking changes in the future. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is capitalized almost everywhere else. It's important to be consistent.
Suggested change
|
||||||||||
|
||||||||||
Generates a CDK application from an existing JSON/YAML CloudFormation template. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this and the sentences below are in paragraph form, not bullet form, these should be complete sentences. |
||||||||||
Takes a valid CloudFormation template as input from either a local file specified with `--from-path`, | ||||||||||
or from a deployed Cloudformation stack using `--from-stack`. Generates a CDK application | ||||||||||
HBobertz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
which will synthesize a CloudFormation template with identical resource configurations to the provided template. | ||||||||||
The generated application will be initialized in the current working directory with a single stack where | ||||||||||
the stack, app, and directory will all be named using the provided `--stack-name`. The generated application will | ||||||||||
be within a generated subdirectory in your current working directory unless `--output-path` is specified. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe note somewhere in here that if a directory already exists with the stack name at the output path (or currently directory) it will be replaced with the new app folder. |
||||||||||
All CDK supported lanaguages are supported, language choice can be specified with `--language`. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#### Generate a typescript application from a local template.json file | ||||||||||
comcalvi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```console | ||||||||||
$ # template.json is a valid cloudformation template in the local directory | ||||||||||
$ cdk migrate --from-path ./template.json --stack-name MyAwesomeApplication | ||||||||||
``` | ||||||||||
|
||||||||||
This command will generate a new direcotry named `MyAwesomeApplication` within your current working directory, and | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
then initialize a new CDK application within that directory which has the same resource configuration as the | ||||||||||
as the provided template.json | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
This results in a CDK application with the following structure, where the lib directory contains a stack definition | ||||||||||
with the same resource configuration as the provided template.json. | ||||||||||
|
||||||||||
```console | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also doesn't match the command you provide above. Both the naming and the language are different. |
||||||||||
├── README.md | ||||||||||
├── bin | ||||||||||
│ └── my_awesome_application.ts | ||||||||||
├── cdk.json | ||||||||||
├── cdk.out | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove cdk.out since it won't exist until after synth? |
||||||||||
│ ├── MyAwesomeApplication.assets.json | ||||||||||
│ ├── MyAwesomeApplication.template.json | ||||||||||
│ ├── cdk.out | ||||||||||
│ ├── manifest.json | ||||||||||
│ ├── synth.lock | ||||||||||
│ └── tree.json | ||||||||||
├── jest.config.js | ||||||||||
├── lib | ||||||||||
│ └── my_awesome_application-stack.ts | ||||||||||
``` | ||||||||||
|
||||||||||
#### Generate a python application from a deployed stack | ||||||||||
|
||||||||||
If you already had a cloudformation stack deployed in your account and would like to migrate to using CDK instead of Cloudformation. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
You can use the `--from-stack` option to generate the application. In this case the `--stack-name` must match the name of the deployed stack. | ||||||||||
|
||||||||||
```console | ||||||||||
$ # generate a python application from MyDeployedStack in your acount | ||||||||||
$ cdk bootstrap migrate --stack-name MyDeployedStack --language python --from-stack | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. woops good catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one still needs to be fixed |
||||||||||
``` | ||||||||||
|
||||||||||
This will generate a python CDK application which will synthesize to the same configuration of resources as the deployed stack. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#### **CDK Migrate Limitations** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to call out support for Custom Resources. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this and nested stacks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and ADC regions will depend on those resources existing in those regions. The app will still synth but may not deploy |
||||||||||
|
||||||||||
CDK Migrate does not currently support nested stacks, Custom resources, or ForEach intrinsic function. | ||||||||||
HBobertz marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
CDK Migrate will only generate L1 constructs and does not currently support any higher level abstractions. | ||||||||||
CDK Migrate succesfully generating an application does *not* guarantee the application is immediately deployable. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make this section bullet points for easier reading. |
||||||||||
It simply generates a CDK application which will synthesize a template that has identical resource configurations | ||||||||||
to the provided template. CDK Migrate does not interact with the CloudFormation service to verify the template | ||||||||||
provided can deploy on it's own, nor does it validate that any resources in the provided template are already managed | ||||||||||
HBobertz marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
in other CloudFormation Templates. In practice this is how CDK Migrate generated applications will | ||||||||||
operate in the following scenarios: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also call out that if the template has has parameters without default values, the customer will need to fill those in manually |
||||||||||
|
||||||||||
##### **The provided template is already deployed to cloudformation in the account/region** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
If the provided template came directly from a deployed cloudformation stack, and that stack has not experienced any drift, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
then the generated application will be immediately deployable, and will not cause any changes to the deployed resources. | ||||||||||
Drift might occur if a resource in your template was modified outside of CloudFormation, namely via the console or CLI. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
##### **The provided template is not deployed to cloudformation in the account/region, and there *is not* overlap with with resources outside the template** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
If the provided template represents a set of resources that have no overlap with resources already deployed in the account/region, | ||||||||||
then the generated application will be immediately deployable. A common reason for this might be because the template came | ||||||||||
from a stack deployed in another account/region. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A common reason for what? |
||||||||||
|
||||||||||
In practice this means for any resource in the provided template. i.e. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "i.e." means "that is", and "e.g." means "for example". I think it's better not to use those anyway.
Suggested change
|
||||||||||
|
||||||||||
```Json | ||||||||||
"S3Bucket": { | ||||||||||
"Type": "AWS::S3::Bucket", | ||||||||||
"Properties": { | ||||||||||
"BucketName": "MyBucket", | ||||||||||
"AccessControl": "PublicRead", | ||||||||||
}, | ||||||||||
"DeletionPolicy": "Retain" | ||||||||||
} | ||||||||||
``` | ||||||||||
|
||||||||||
There must not exist a resource of that type with the same name aka "MyBucket" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
##### **The provided template is not deployed to cloudformation in the account/region, and there *is* overlap with with resources outside the template** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
If the provided template represents a set of resources that have overlap with resources already deployed in the account/region, | ||||||||||
then the generated application will not be immediately deployable. If those overlapped resources are already managed by | ||||||||||
another CloudFormation stack in that account/region, then those resources will need to be manually removed from the provided | ||||||||||
template. Otherwise, if the overlapped resources are not managed by another CloudFormation stack, then first run remove those | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some words missing here? I'm not sure what this part is supposed to say. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Github is highlighting too many lines. I'm asking about this part "Otherwise, if the overlapped resources are not managed by another CloudFormation stack, then first run remove those" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the change should be here. |
||||||||||
resources and deploy the template successfully, then re-add them and run `cdk import` to import them into your deployed stack. | ||||||||||
|
||||||||||
### `cdk destroy` | ||||||||||
|
||||||||||
Deletes a stack from it's environment. This will cause the resources in the stack to be destroyed (unless they were | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to open with this, but immediately below should be a paragraph explaining what this command does at a high level, including an example of simplest, minimal usage, eg only using required flags / options. It should explain where the output goes and what the output is. I should not have to guess if it's a full CDK directory or if it's a single stack file.