Skip to content

aws-lambda: Inconsistent inputDir Behavior between NodejsFunction and RustFunction #34058

Open
@garysassano

Description

@garysassano

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions