(cli): watch command not working properly with NodeJsFunction #17391
Labels
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p2
package/tools
Related to AWS CDK Tools or CLI
What is the problem?
Hi, I tried new
cdk watch
command but it's not working as expected. Here's the detail:When we
cdk watch
a stack with a NodeJsFunction, the resulting asset of Lambda code becomes broken.Note that
cdk deploy --watch
seems working fine, so it isn't a big issue.Reproduction Steps
cdk watch
a stack with NodeJsFunction, and then modifylambdas/handler/index.ts
to trigger a new deploy.in
lambdas/handler/
directory, there is only a fileindex.ts
What did you expect to happen?
The resulting asset contains only files related to the Lambda function such as
index.js
.What actually happened?
The resulting asset contains all the files in the CDK root directory.
CDK CLI Version
1.131.0
Framework Version
1.131.0
Node.js Version
v14.15.0
OS
macOS
Language
Typescript
Language Version
No response
Other information
I found why it's happening as below:
When synthesizing assets, bundling code is skipped because
skip = true
is passed. When skipped, the resulting asset would become entire CDK root directory in my case.aws-cdk/packages/@aws-cdk/core/lib/asset-staging.ts
Lines 305 to 320 in d231b9e
the
skip
flag becomestrue
becausethis.node.tryGetContext(cxapi.BUNDLING_STACKS)
is[]
aws-cdk/packages/@aws-cdk/core/lib/asset-staging.ts
Lines 189 to 194 in d231b9e
this.node.tryGetContext(cxapi.BUNDLING_STACKS)
is[]
becauseBUNDLING_COMMANDS
does not includewatch
command.aws-cdk/packages/aws-cdk/lib/settings.ts
Lines 253 to 261 in d231b9e
aws-cdk/packages/aws-cdk/lib/settings.ts
Lines 35 to 40 in d231b9e
So I guess we can solve this issue by something like adding
watch
toBUNDLING_COMMANDS
array. (I don't know if there'd be some side effects though...)btw it worked well with
cdk deploy --watch
command, thanks for a great new feature!The text was updated successfully, but these errors were encountered: