aws-lambda: Inconsistent `inputDir` Behavior between `NodejsFunction` and `RustFunction`
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
The `inputDir` parameter in AWS CDK function constructs works differently depending on which construct is used:
- In `NodejsFunction`, the `inputDir` starts from the root of your entire project
- In `RustFunction`, the `inputDir` starts from the path of the function source (more intuitive)
This inconsistency creates confusion when trying to use the same patterns across different function types in the same project.
## Example
When using a `NodejsFunction`:
```typescript
const clientNodeLambda = new NodejsFunction(this, "ClientNodeLambda", {
functionName: "client-node-lambda",
entry: join(__dirname, "../functions/client-node", "index.ts"),
bundling: {
commandHooks: {
beforeBundling() {
return [];
},
afterBundling(inputDir: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}/bins/telemetry-exporter/otel-dist`,
`cp ${inputDir}/src/functions/client-node/bins/collector ${outputDir}/bins/telemetry-exporter/otel-dist/`,
];
},
beforeInstall() {
return [];
},
},
},
});
```
Whereas in `RustFunction`:
```typescript
const clientRustLambda = new RustFunction(this, "ClientRustLambda", {
functionName: "client-rust-lambda",
manifestPath: join(__dirname, "../functions/client-rust", "Cargo.toml"),
bundling: {
cargoLambdaFlags: ["--quiet"],
commandHooks: {
beforeBundling() {
return [];
},
afterBundling(inputDir: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}/bins/telemetry-exporter/otel-dist`,
`cp ${inputDir}/bins/collector ${outputDir}/bins/telemetry-exporter/otel-dist/`,
];
},
},
},
});
```
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
See above.
### Current Behavior
See above.
### Reproduction Steps
See above.
### Possible Solution
Ideally, the `NodejsFunction` should be updated to match the behavior of `RustFunction` where `inputDir` points to the function source directory rather than the project root.
### Additional Information/Context
_No response_
### CDK CLI Version
2.187.0
### Framework Version
_No response_
### Node.js Version
22.14.0
### OS
Ubuntu 24.04
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start with the NodejsFunction and RustFunction bundling entry points, focusing on the afterBundling(inputDir, outputDir) command hooks shown in the issue. Reproduce both examples and compare how each construct establishes inputDir. Done means the two constructs have consistent, documented inputDir behavior with coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, rust, typescript
- Domain
- build-system, cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100