Make `NodejsFunction` L2 construct as injectable
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Background
This issue is a follow-up to [#34486](https://github.com/aws/aws-cdk/issues/34486) which was temporarily fixed by [PR #34498](https://github.com/aws/aws-cdk/pull/34498). The temporary fix removed the usage of Injectable decorator from `NodejsFunction` L2 construct.
### Problem
The current implementation of `findDefiningFile` in `NodejsFunction` doesn't correctly handle cases where decorators are used. This leads to incorrect file path resolution when trying to determine the source file for a Lambda function.
### Proposed Solutions
There are two potential approaches to properly fix this issue:
1. **Remove the decorator pattern entirely**:
- Replace the decorator with direct injection logic similar to what's done in RestApi
- Reference implementation: [aws-cdk/aws-apigateway/lib/restapi.ts#L1143-L1170](https://github.com/aws/aws-cdk/blob/8d8c120fa673af75cbde7a8bec6b4f2b4c44f4af/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts#L1143-L1170)
- This would be a more straightforward approach but changes the API design pattern
2. **Enhance the findDefiningFile function** (RECOMMENDED):
- Modify the function to correctly handle decorator patterns
- Current implementation: [aws-cdk/aws-lambda-nodejs/lib/function.ts#L279-L295](https://github.com/aws/aws-cdk/blob/8d8c120fa673af75cbde7a8bec6b4f2b4c44f4af/packages/aws-cdk-lib/aws-lambda-nodejs/lib/function.ts#L279-L295)
- This would preserve the current API design but requires more complex changes to the file resolution logic
Contributor guide
Research direction
Start in packages/aws-cdk-lib/aws-lambda-nodejs/lib/function.ts, especially findDefiningFile around lines 279-295, and compare the direct injection pattern in packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts around lines 1143-1170. Determine how decorator usage affects source-file resolution, then verify that NodejsFunction remains injectable and resolves the correct Lambda source file when decorators are used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100