Skip to content
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

aws-cdk-lib: Add a reference to the unbundled Lambda handler's path from the resource metadata #27402

Open
1 of 2 tasks
ljacobsson opened this issue Oct 4, 2023 · 1 comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@ljacobsson
Copy link

Describe the feature

Currently when I synth a NodejsFunction, I get this metadata on the resulting resource the synthesised template:

   "Metadata": {
    "aws:cdk:path": "SampCdkDebugLambdaStack/test/Resource",
    "aws:asset:path": "asset.11ac1322337610dc36d495221575c8a1fd592b28720a47840bdc876c15031d78",
    "aws:asset:is-bundled": true,
    "aws:asset:property": "Code",
   }

I see use cases for an additional metadata item that provides a reference back to the original unbundled source file:

    "aws:asset:source-path": "../src/my-function.ts"

Use Case

A user might have limited knowledge of the stack and want to locate the source code for MyFunction123. Currently they'll get pointed to the asset folder which contains minified code. With the suggested additional property there'll be a two way tracability.

My personal usecase is slightly different. I maintain samp-cli which has a command for local debugging of Lambda funcitons. This is different from sam local and gets triggered from real cloud events via MQTT. The challenge is to map an incoming event with the Lambda handler on disk. I could make it invoke the code in the CDK generated asset folders, but I'd lose the fast reloads I get when I don't have to cdk synth after each change.

Here's an image illustrating this. It's the red dotted line that I want to solve
image

I've been looking at using sourcemaps for this, but there's no way to identify the lambda entry point in the list of source files it provides.

Proposed Solution

Add "aws:asset:source-path": "../src/my-function.ts" to the resource's metadata

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.96.1

Environment details (OS name and version, etc.)

Ubuntu 20.04

@ljacobsson ljacobsson added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2023
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Oct 4, 2023
@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2023
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Oct 4, 2023

Hey, thanks for the request. This doesn't seem like it should be super hard to do, though I'm not sure on some of the details without diving into it. Maybe it's as simple to implement as it appears

As always, you can use escape hatches to access the L1 construct you need to, and can add a section to the metadata of a resource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants