From b34bd6de5671948b2fdd6373c017c99a15cbaf20 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 14 Oct 2021 16:21:18 -0700 Subject: [PATCH 1/3] chore: add settings for the "cdk watch" command --- text/0001-cdk-update.md | 64 ++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/text/0001-cdk-update.md b/text/0001-cdk-update.md index fa44b85e5..303b7c4cf 100644 --- a/text/0001-cdk-update.md +++ b/text/0001-cdk-update.md @@ -67,14 +67,58 @@ Checking stack DataStack for possible hotswap update Watching stack inputs for changes: * LambdaFunction[Appfunction]: * LambdaFunction[StreamFunction]: - ``` -The watcher can only watch for file changes. For Lambda code, that means that -directories will be watched for changes and zipped if they change. If the file -asset is a zip file, then the update will fire whenever that changes. The -existing docker asset builder will be used to watch for changes in local docker -images. +The "watch" functionality can be customized by setting a few new options in your `cdk.json` file: + +1. If either your CDK code, or your runtime code + (like the code of your Lambda functions) + needs to go through a build step before invoking `cdk deploy`, + you can specify that command in the new `"build"` key. Example: + + ```json + { + "app": "mvn exec:java", + "build": "mvn package" + } + ``` + + If the `"build"` key is present in the `cdk.json` file, + the "watch" process will invoke the specified command before performing synthesis. + If your build process is more complex than just a single command, + `"build"` also accepts an array of commands: + + ```json + { + "app": "node bin/app.js", + "build": [ + "yarn --cwd src/lambda-code build", + "yarn build" + ] + } + ``` + + The commands will be executed one after the other, + in the same order as they were declared in the `cdk.json` file. + +2. The "watch" process needs to know which files and directories to observe for changes, + and which ones to ignore. You can customize these using the `"include"` and `"exclude"` + sub-keys of the new `"watch"` top-level key: + + ```json + { + "app": "mvn exec:java", + "build": "mvn package", + "watch": { + "include": ["src", "lambda/code/**/*"], + "exclude": ["cdk.out", "target"] + } + } + ``` + + The `cdk init` command fills these out for you, + so if your project has a standard layout, + you shouldn't need to modify these from the generated defaults. In addition to the monitoring mode, it is possible to perform one-shot hotswap deployments on some or all of the stacks in the CDK application: @@ -123,18 +167,12 @@ Deploying DataStack Done! ``` -In addition to running in a one shot mode, the `cdk deploy --hotswap` -command also has a `--watch` command line option that enable it to monitor the -assets on disk and perform an update when they change. - #### Resource Support - AWS Lambda `Function` - file and directory assets - StepFunction - - Workflow definitions -- AWS Fargate - - image assets + - State Machine definitions - ECS - image assets From 0f7b72934c6f8d98acaa919436e185a68d7b7e5a Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 18 Oct 2021 17:38:37 -0700 Subject: [PATCH 2/3] Elad's comments. --- text/0001-cdk-update.md | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/text/0001-cdk-update.md b/text/0001-cdk-update.md index 303b7c4cf..8f3595e8e 100644 --- a/text/0001-cdk-update.md +++ b/text/0001-cdk-update.md @@ -84,26 +84,13 @@ The "watch" functionality can be customized by setting a few new options in your ``` If the `"build"` key is present in the `cdk.json` file, - the "watch" process will invoke the specified command before performing synthesis. - If your build process is more complex than just a single command, - `"build"` also accepts an array of commands: - - ```json - { - "app": "node bin/app.js", - "build": [ - "yarn --cwd src/lambda-code build", - "yarn build" - ] - } - ``` - - The commands will be executed one after the other, - in the same order as they were declared in the `cdk.json` file. + `cdk synth` (which the "watch" process invokes before deployment) + will execute the specified command before performing synthesis. 2. The "watch" process needs to know which files and directories to observe for changes, and which ones to ignore. You can customize these using the `"include"` and `"exclude"` - sub-keys of the new `"watch"` top-level key: + sub-keys of the new `"watch"` top-level key. + Values are glob patterns that are matched _relative to the location of the `cdk.json`_ directory: ```json { From f71f261858cc65efdd48d1b7a413844980cc69b6 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Tue, 19 Oct 2021 18:01:43 -0700 Subject: [PATCH 3/3] Always exclude the CDK output directory implicitly. --- text/0001-cdk-update.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/text/0001-cdk-update.md b/text/0001-cdk-update.md index 8f3595e8e..73144e76e 100644 --- a/text/0001-cdk-update.md +++ b/text/0001-cdk-update.md @@ -97,8 +97,8 @@ The "watch" functionality can be customized by setting a few new options in your "app": "mvn exec:java", "build": "mvn package", "watch": { - "include": ["src", "lambda/code/**/*"], - "exclude": ["cdk.out", "target"] + "include": ["./**"], + "exclude": ["target"] } } ``` @@ -106,6 +106,8 @@ The "watch" functionality can be customized by setting a few new options in your The `cdk init` command fills these out for you, so if your project has a standard layout, you shouldn't need to modify these from the generated defaults. + Also note that the output directory (`cdk.out` by default) + is always automatically excluded, so doesn't need to be specified in the `cdk.json` file. In addition to the monitoring mode, it is possible to perform one-shot hotswap deployments on some or all of the stacks in the CDK application: