aws / aws/aws-cdk

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

Open
#27,402 2 comments 0 reactions 0 assignees View on GitHub
aws-cdk-lib effort/small feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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](https://github.com/ljacobsson/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](https://github.com/aws/aws-cdk/assets/7579097/49b353f6-848d-4767-b13d-b334daa0e7b5)

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

- [X] 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

Contributor guide

Open the contributing guide

Research direction

The issue names NodejsFunction and the synthesized resource Metadata, but no implementation files or tests. Start by tracing how NodejsFunction produces the asset metadata during synth, then verify the generated template. Done means the metadata includes a reliable reference to the original unbundled handler path.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.