aws-cdk 2.1118.4 → 2.1120.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,11 +17,13 @@ The AWS CDK Toolkit provides the `cdk` command-line interface that can be used t
17
17
  | [`cdk init`](#cdk-init) | Start a new CDK project (app or library) |
18
18
  | [`cdk list`](#cdk-list) | List stacks and their dependencies in an application |
19
19
  | [`cdk synth`](#cdk-synth) | Synthesize a CDK app to CloudFormation template(s) |
20
+ | [`cdk diagnose`](#cdk-diagnose) | Diagnose a failed stack's root cause |
20
21
  | [`cdk diff`](#cdk-diff) | Diff stacks against current state |
21
22
  | [`cdk deploy`](#cdk-deploy) | Deploy a stack into an AWS account |
22
23
  | [`cdk publish-assets`](#cdk-publish-assets) | Publish assets for stack(s) without deploying |
23
24
  | [`cdk rollback`](#cdk-rollback) | Roll back a failed deployment |
24
25
  | [`cdk import`](#cdk-import) | Import existing AWS resources into a CDK stack |
26
+ | [`cdk orphan`](#cdk-orphan) | Detach resources from a stack without deleting them |
25
27
  | [`cdk migrate`](#cdk-migrate) | Migrate AWS resources, CloudFormation stacks, and CloudFormation templates to CDK |
26
28
  | [`cdk watch`](#cdk-watch) | Watches a CDK app for deployable and hotswappable changes |
27
29
  | [`cdk destroy`](#cdk-destroy) | Deletes a stack from an AWS account |
@@ -158,6 +160,30 @@ The `quiet` option can be set in the `cdk.json` file.
158
160
  See the [AWS Documentation](https://docs.aws.amazon.com/cdk/latest/guide/apps.html#apps_cloud_assembly) to learn more about cloud assemblies.
159
161
  See the [CDK reference documentation](https://docs.aws.amazon.com/cdk/api/latest/docs/cloud-assembly-schema-readme.html) for details on the cloud assembly specification
160
162
 
163
+ ### `cdk diagnose`
164
+
165
+ > [!CAUTION]
166
+ > `cdk diagnose` is under development and therefore must be opted in via the
167
+ > `--unstable` flag: `cdk --unstable=diagnose diagnose`. `--unstable` indicates
168
+ > that the scope and API of feature might still change. Otherwise the feature
169
+ > is generally production ready and fully supported.
170
+
171
+ Looks at a failed stack deployment in CloudFormation, and prints the root cause
172
+ reason with pointers to the CDK source code that caused the problem.
173
+
174
+ This peforms the same diagnosis that `cdk deploy` does, but does it
175
+ after-the-fact. This can be useful to refresh your memory, ask a colleague to
176
+ help diagnose a deployment problem, or try to diagnose a deployment problem if
177
+ your way of working dictates that you perform stack deployment via a CI/CD
178
+ system instead of directly using the CDK CLI.
179
+
180
+ ```console
181
+ # Diagnose all stacks found inside the application
182
+ $ cdk --unstable=diagnose diagnose
183
+
184
+ # Diagnose the failed deployment of a specific stack
185
+ $ cdk --unstable=diagnose diagnose <MyStackName>
186
+ ```
161
187
 
162
188
  ### `cdk diff`
163
189
 
@@ -166,10 +192,10 @@ deployed application (or a user-specified CloudFormation template). If you need
166
192
  found you need to use the `--fail` command line option.
167
193
 
168
194
  ```console
169
- $ # Diff against the currently deployed stack
195
+ # Diff against the currently deployed stack
170
196
  $ cdk diff --app='node bin/main.js' MyStackName
171
197
 
172
- $ # Diff against a specific template document
198
+ # Diff against a specific template document
173
199
  $ cdk diff --app='node bin/main.js' MyStackName --template=path/to/template.yml
174
200
  ```
175
201
 
@@ -409,6 +435,11 @@ be deployed and then executes it. This behavior can be controlled with the
409
435
  - `--method=prepare-change-set`: create the change set but don't execute it.
410
436
  This is useful if you have external tools that will inspect the change set or
411
437
  you have an approval process for change sets.
438
+ - `--method=execute-change-set`: execute a previously created change set. This
439
+ bypasses change set creation and asset publishing entirely. Requires exactly
440
+ one stack name. Defaults to the `cdk-deploy-change-set` change set name if
441
+ `--change-set-name` is not provided. This is useful for two-step deployment
442
+ workflows where you first review a change set and then execute it.
412
443
  - `--method=direct`: do not create a change set but apply the change immediately.
413
444
  This is typically a bit faster than creating a change set, but it loses
414
445
  the progress information.
@@ -428,8 +459,23 @@ set to make it easier to later execute:
428
459
  $ cdk deploy --method=prepare-change-set --change-set-name MyChangeSetName
429
460
  ```
430
461
 
431
- For more control over when stack changes are deployed, the CDK can generate a
432
- CloudFormation change set but not execute it.
462
+ To review a change set before executing it, use a two-step workflow:
463
+
464
+ ```console
465
+ $ # Step 1: Create the change set without executing it
466
+ $ cdk deploy MyStack --method=prepare-change-set
467
+
468
+ $ # Step 2: Review the change set (e.g., in the AWS Console or via CLI)
469
+
470
+ $ # Step 3: Execute the change set
471
+ $ cdk deploy MyStack --method=execute-change-set
472
+ ```
473
+
474
+ A custom change set name can be provided with `--change-set-name` in both steps.
475
+
476
+ When using `--method=execute-change-set`, the options `--force`, `--parameters`,
477
+ `--import-existing-resources`, and `--revert-drift` cannot be used
478
+ since the change set has already been created.
433
479
 
434
480
  #### Import existing resources
435
481
 
@@ -460,9 +506,9 @@ $ cdk deploy --import-existing-resources --exclusively StackName
460
506
  ```
461
507
 
462
508
  Only resources that have custom names can be imported using `--import-existing-resources`.
463
- For more information, see [name type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-name.html).
509
+ For more information, see [name type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-name.html).
464
510
  To import resources that do not accept custom names, such as EC2 instances,
465
- use the `cdk import` instead.
511
+ use the `cdk import` instead.
466
512
  Visit [Bringing existing resources into CloudFormation management](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html)
467
513
  for more details.
468
514
 
@@ -792,6 +838,73 @@ This feature currently has the following limitations:
792
838
  IAM permissions to the `deploy-role`.
793
839
 
794
840
 
841
+ ### `cdk orphan`
842
+
843
+ > `cdk orphan` is currently experimental, meaning we reserve the right to change
844
+ > options and flag names in the future. Pass the `--unstable=orphan` flag when using
845
+ > this command and be aware of this when using it in scripts.
846
+
847
+ Safely detaches one or more resources from a CloudFormation stack without deleting them.
848
+ This is useful when you need to migrate a resource from one construct type to another
849
+ (for example, migrating a DynamoDB `Table` to `TableV2`) without any downtime or data loss.
850
+
851
+ The orphan command works by:
852
+
853
+ 1. Resolving cross-resource references (`Ref`, `Fn::GetAtt`, `Fn::Sub`) to the orphaned resources, so that other resources in the stack that depend on them continue to work after the orphaned resources are removed
854
+ 2. Setting the `DeletionPolicy` to `Retain`, replacing all cross-resource references with literal values, and removing `DependsOn` entries to isolate the resources from the rest of the stack
855
+ 3. Removing the resources from the CloudFormation template (they continue to exist in your AWS account)
856
+
857
+ After orphaning, you can update your CDK code and use `cdk import` to bring the resource back under management with the new construct type.
858
+
859
+ All construct paths must reference the same stack. Wildcard patterns are not supported; paths are matched as exact prefixes.
860
+
861
+ ```console
862
+ $ # Orphan a single resource
863
+ $ cdk orphan --unstable=orphan MyStack/MyTable
864
+
865
+ $ # Orphan multiple resources
866
+ $ cdk orphan --unstable=orphan MyStack/MyTable MyStack/MyBucket
867
+ ```
868
+
869
+ #### Example: Migrating DynamoDB Table to TableV2
870
+
871
+ 1. Deploy your stack with the original `Table` construct:
872
+
873
+ ```ts
874
+ const table = new dynamodb.Table(this, 'MyTable', {
875
+ tableName: 'my-table',
876
+ partitionKey: { name: 'PK', type: dynamodb.AttributeType.STRING },
877
+ });
878
+ ```
879
+
880
+ 2. Orphan the table from the stack:
881
+
882
+ ```console
883
+ $ cdk orphan --unstable=orphan MyStack/MyTable
884
+ ```
885
+
886
+ The command outputs next steps including a `cdk import` command with the resource mapping.
887
+
888
+ 3. Update your CDK code to use `TableV2`:
889
+
890
+ ```ts
891
+ const table = new dynamodb.TableV2(this, 'MyTable', {
892
+ tableName: 'my-table',
893
+ partitionKey: { name: 'PK', type: dynamodb.AttributeType.STRING },
894
+ });
895
+ ```
896
+
897
+ 4. Import the existing table into the new construct:
898
+
899
+ ```console
900
+ $ cdk import --resource-mapping-inline '{"MyTable794EDED1":{"TableName":"my-table"}}'
901
+ ```
902
+
903
+ The import command will show any pending drift and offer to run `cdk deploy` afterwards to reconcile it.
904
+
905
+ The table remains available throughout the entire process with zero downtime.
906
+
907
+
795
908
  ### `cdk migrate`
796
909
 
797
910
  ⚠️**CAUTION**⚠️: CDK Migrate is currently experimental and may have breaking changes in the future.
@@ -1056,9 +1169,9 @@ cdk bootstrap --no-previous-parameters
1056
1169
  CDK Garbage Collection.
1057
1170
 
1058
1171
  > [!CAUTION]
1059
- > CDK Garbage Collection is under development and therefore must be opted in via the
1060
- >`--unstable` flag: `cdk gc --unstable=gc`. `--unstable` indicates that the scope and
1061
- > API of feature might still change. Otherwise the feature is generally production
1172
+ > CDK Garbage Collection is under development and therefore must be opted in via the
1173
+ >`--unstable` flag: `cdk gc --unstable=gc`. `--unstable` indicates that the scope and
1174
+ > API of feature might still change. Otherwise the feature is generally production
1062
1175
  > ready and fully supported.
1063
1176
 
1064
1177
  `cdk gc` garbage collects unused assets from your bootstrap bucket via the following mechanism:
@@ -1171,12 +1284,12 @@ $ cdk doctor
1171
1284
 
1172
1285
  ### `cdk refactor`
1173
1286
 
1174
- ⚠️**CAUTION**⚠️: CDK Refactor is currently experimental and may have
1175
- breaking changes in the future. Make sure to use the `--unstable=refactor` flag
1287
+ ⚠️**CAUTION**⚠️: CDK Refactor is currently experimental and may have
1288
+ breaking changes in the future. Make sure to use the `--unstable=refactor` flag
1176
1289
  when using this command.
1177
1290
 
1178
- Compares the infrastructure specified in the current state of the CDK app with
1179
- the currently deployed application, to determine if any resource was moved
1291
+ Compares the infrastructure specified in the current state of the CDK app with
1292
+ the currently deployed application, to determine if any resource was moved
1180
1293
  (to a different stack or to a different logical ID, or both). In keeping with
1181
1294
  the CloudFormation API, you are not allowed to modify the set of resources
1182
1295
  as part of a refactor. In other words, adding, deleting or updating resources
@@ -1200,9 +1313,9 @@ The following resources were moved or renamed:
1200
1313
  └───────────────────────────────┴───────────────────────────────┴───────────────────────────────────┘
1201
1314
  ```
1202
1315
 
1203
- Note the use of the `--dry-run` flag. When this flag is used, the CLI will
1204
- show this table and exit. Eventually, the CLI will also be able to automatically
1205
- apply the refactor on your CloudFormation stacks. But for now, only the dry-run
1316
+ Note the use of the `--dry-run` flag. When this flag is used, the CLI will
1317
+ show this table and exit. Eventually, the CLI will also be able to automatically
1318
+ apply the refactor on your CloudFormation stacks. But for now, only the dry-run
1206
1319
  mode is supported.
1207
1320
 
1208
1321
  If your application has more than one stack, and you want the `refactor`
@@ -1210,7 +1323,7 @@ command to consider only a subset of them, you can specify the stacks you
1210
1323
  want, both local and deployed:
1211
1324
 
1212
1325
  ```shell
1213
- $ cdk refactor Test* ProdStack --unstable=refactor --dry-run
1326
+ $ cdk refactor Test* ProdStack --unstable=refactor --dry-run
1214
1327
  ```
1215
1328
 
1216
1329
  This is useful if, for example, you have more than one CDK application deployed
@@ -1246,8 +1359,8 @@ Detected ambiguities:
1246
1359
  ```
1247
1360
 
1248
1361
  You can resolve this ambiguity manually, by passing an override file via the
1249
- `--override-file=<path>` CLI option. This file should contain a JSON object
1250
- with the following structure:
1362
+ `--override-file=<path>` CLI option. This file should contain a JSON object
1363
+ with the following structure:
1251
1364
 
1252
1365
  ```json
1253
1366
  {
@@ -1273,7 +1386,7 @@ that is not already occupied by any resource.
1273
1386
 
1274
1387
  To determine if a resource was moved or renamed, the CLI computes a digest
1275
1388
  for each resource, both in the deployed stacks and in the local stacks, and
1276
- then compares the digests.
1389
+ then compares the digests.
1277
1390
 
1278
1391
  Conceptually, the digest is computed as:
1279
1392
 
@@ -1281,19 +1394,19 @@ Conceptually, the digest is computed as:
1281
1394
  digest(resource) = hash(type + properties + dependencies.map(d))
1282
1395
  ```
1283
1396
 
1284
- where hash is a cryptographic hash function. In other words, the digest of a
1285
- resource is computed from its type, its own properties (that is, excluding
1286
- properties that refer to other resources), and the digests of each of its
1287
- dependencies. The digest of a resource, defined recursively this way, remains
1288
- stable even if one or more of its dependencies gets renamed. Since the
1289
- resources in a CloudFormation template form a directed acyclic graph, this
1397
+ where hash is a cryptographic hash function. In other words, the digest of a
1398
+ resource is computed from its type, its own properties (that is, excluding
1399
+ properties that refer to other resources), and the digests of each of its
1400
+ dependencies. The digest of a resource, defined recursively this way, remains
1401
+ stable even if one or more of its dependencies gets renamed. Since the
1402
+ resources in a CloudFormation template form a directed acyclic graph, this
1290
1403
  function is well-defined.
1291
1404
 
1292
1405
  Resources that have the same digest, but different locations, are considered to be
1293
1406
  the same resource, and therefore to have been moved or renamed.
1294
1407
 
1295
1408
  #### Limitations
1296
- - A refactor cannot leave a stack empty. This is a CloudFormation API limitation,
1409
+ - A refactor cannot leave a stack empty. This is a CloudFormation API limitation,
1297
1410
  that also applies to deployments.
1298
1411
  - Creation of new stacks during a refactor is not supported. If you need to
1299
1412
  create a new stack, do it in a separate deployment, previous to refactoring.
@@ -1318,7 +1431,7 @@ option.
1318
1431
 
1319
1432
  ```console
1320
1433
  $ # Detect drift against the currently-deployed stack with the verbose flag enabled
1321
- $ cdk drift --verbose
1434
+ $ cdk drift --verbose
1322
1435
  ```
1323
1436
 
1324
1437
  ### `cdk cli-telemetry`
@@ -1345,7 +1458,7 @@ that can be set in many different ways (such as `~/.cdk.json`).
1345
1458
  $ # Check the current status of telemetry
1346
1459
  $ cdk cli-telemetry --status
1347
1460
  ```
1348
- ### `cdk flags`
1461
+ ### `cdk flags`
1349
1462
 
1350
1463
  View and modify your feature flag configurations.
1351
1464
 
@@ -1369,7 +1482,7 @@ Alternatively, you can also run `cdk flags --all` to see a report of all feature
1369
1482
  3. flags that are not configured at all
1370
1483
 
1371
1484
  ```shell
1372
- $ cdk flags --unstable=flags --all
1485
+ $ cdk flags --unstable=flags --all
1373
1486
  Feature Flag Recommended User
1374
1487
  @aws-cdk/... true true
1375
1488
  * @aws-cdk/... true false
@@ -1394,7 +1507,7 @@ $ cdk flags --unstable=flags --set --recommended --all
1394
1507
  [~] AWS::S3::Bucket MyBucket
1395
1508
  └─ [~] Properties
1396
1509
  └─ [~] Encryption
1397
- ...
1510
+ ...
1398
1511
  Number of stacks with differences: 2
1399
1512
  Do you want to accept these changes? (y/n) y
1400
1513
  Resynthesizing...
@@ -1429,7 +1542,7 @@ $ cdk flags --unstable=flags --set --default --unconfigured
1429
1542
  * @aws-cdk/... true <unset>
1430
1543
  * @aws-cdk/... true <unset>
1431
1544
  Synthesizing...
1432
-
1545
+
1433
1546
  Do you want to accept these changes? (y/n) y
1434
1547
  Resynthesizing...
1435
1548
  ```
@@ -1438,7 +1551,7 @@ $ cdk flags --unstable=flags --set --default --unconfigured
1438
1551
 
1439
1552
  #### View more information about a flag
1440
1553
 
1441
- Besides running `cdk flags` and `cdk flags --all` to view your feature flag configuration, you can also utilize `cdk flags "#FLAGNAME#"` to inspect a specific feature flag and find out what a specific flag does. This can be helpful in cases where you want to understand a particular flag and its impact on your application.
1554
+ Besides running `cdk flags` and `cdk flags --all` to view your feature flag configuration, you can also utilize `cdk flags "#FLAGNAME#"` to inspect a specific feature flag and find out what a specific flag does. This can be helpful in cases where you want to understand a particular flag and its impact on your application.
1442
1555
 
1443
1556
  ```shell
1444
1557
  $ cdk flags --unstable=flags "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021"
@@ -1449,7 +1562,7 @@ $ cdk flags --unstable=flags "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1
1449
1562
 
1450
1563
  #### Filter flags by substring
1451
1564
 
1452
- You can also run `cdk flags #substring#` to view all matching feature flags. If there is only one feature flag that matches that substring, specific details will be displayed.
1565
+ You can also run `cdk flags #substring#` to view all matching feature flags. If there is only one feature flag that matches that substring, specific details will be displayed.
1453
1566
 
1454
1567
  ```shell
1455
1568
  $ cdk flags --unstable=flags ebs
@@ -1486,7 +1599,7 @@ $ cdk flags --unstable=flags--set "@aws-cdk/aws-cloudfront:defaultSecurityPolicy
1486
1599
  - ...
1487
1600
  Number of stacks with differences: 2
1488
1601
  Do you want to accept these changes? (y/n) y
1489
- Resynthesizing...
1602
+ Resynthesizing...
1490
1603
  ```
1491
1604
 
1492
1605
  ## Global Options