Open
Description
Describe the bug
The inputDir
parameter in AWS CDK function constructs works differently depending on which construct is used:
- In
NodejsFunction
, theinputDir
starts from the root of your entire project - In
RustFunction
, theinputDir
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
:
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
:
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