Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
garysassano opened this issue Apr 5, 2025 · 1 comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@garysassano
Copy link
Contributor

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

@garysassano garysassano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2025
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 5, 2025
@pahud
Copy link
Contributor

pahud commented Apr 5, 2025

Current vs Expected Behavior

Current

Image

Expected

Image

Yes we should align the inputDir logic for similar bundling experience.

Making this a p2 and requesting the maintainer for inputs.

@pahud pahud added p2 effort/medium Medium work item – several days of effort @aws-cdk/aws-lambda-nodejs and removed needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants