aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.68k stars 3.93k forks source link

[aws-lambda-nodejs] LambdaNodeJs bundles lambda code into cdk.staging directory when using cdk synth --no-staging #9189

Open dave-graham opened 4 years ago

dave-graham commented 4 years ago

When cdk synth --no-staging is run, it should still refer to the lambda file that has been developed, to enable local development and debugging.

I would expect the aws:asset:path to still refer to the original file, rather than bundled version when adding --no-staging, but it's looking like:

aws:asset:path: /Users/user-name/path-to-project/.cdk.staging/asset-bundle-L5zSs8

This is preventing me from using breakpoints in vscode to debug, using for example:

echo '{}' | sam local invoke -d 9999 ServerlessFunctionName

Or even just general debugging, as I need to run a cdk synth each time I make a change to the lambda.

Also thanks for the work on lambda-nodejs, it's great, and really simplifies some workflows I would otherwise have to manually put together.

This is :bug: Bug Report

jogold commented 4 years ago

@eladb what do you think here? Should we simply disable bundling when staging is disabled?

if (props.bundling && !stagingDisabled) { https://github.com/aws/aws-cdk/blob/d28752513175c94fb2bc4da43374d7f2e66d6550/packages/%40aws-cdk/core/lib/asset-staging.ts#L91-L93

eladb commented 4 years ago

Feels weird to completely disable asset bundling for all assets (whether they are part of your app or not). Would it make sense to specify which assets we want to skip? This whole behavior around disabling asset staging feels a bit hacky, but the use case of local lambda debugging still stands.

Also, I would include a warning if bundling is disabled.

danielleletartesonos commented 3 years ago

Curious what the status is on this bug? I'm experiencing the same issue.

github-actions[bot] commented 2 years ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

Sevi7 commented 2 years ago

I write this comment so the issue is not closed and can be solved

corymhall commented 2 years ago

@Sevi7 @dave-graham Is this still an issue for you? I'm not sure I follow how you would be able to have the Lambda code updated without re-running synth since synth is what bundles the code?

github-actions[bot] commented 2 years ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

Sevi7 commented 2 years ago

@corymhall I think we did not mention to have the Lambda code updated without re-running synth. We are running synth to have the code updated, the problem is the cloudformation output template should still refer to the lambda file that has been developed instead of the path that it is written (see aws:asset:path):

Metadata:
      aws:cdk:path: shared/kinesis/DataStream/publishKinesisEvents/Resource
      aws:asset:path: /Users/adrian/app-2/packages/service-shared/cdk.out/asset.2bee75b1cdb5b7419c14402cb3dd78ec288cde085122101f6465e4eb1b9429d1
      aws:asset:is-bundled: true
      aws:asset:property: Code

The documentation for cdk synth --staging says:

Copy assets to the output directory (use --no-staging to disable, needed for local debugging the source files with SAM CLI)

And this is not happening. For aws-lambda it works but not for aws-lambda-nodejs as it is the case

corymhall commented 2 years ago

@Sevi7 I'm not super familiar with how SAM CLI works. Does the SAM CLI also perform some bundling? I think the piece that I'm struggling to understand is why you would want it to point to the source code instead of the bundled code.

Sevi7 commented 2 years ago

@corymhall For sam local invoke it is not bundling, it is using the template.yaml generated by cdk synth to invoke locally the lambda in order to debug it. We want the lambdas in the template to point to the source code instead of the bundled code so we can use breakpoints in vscode to debug it (it's impossible to debug bundled code)

bestickley commented 1 year ago

I would like to use this feature for local debugging too with SAM CLI. Any updates @corymhall?