Interface NodejsFunctionProps

All Superinterfaces:
EventInvokeConfigOptions, FunctionOptions, software.amazon.jsii.JsiiSerializable
All Known Implementing Classes:
NodejsFunctionProps.Jsii$Proxy

@Generated(value="jsii-pacmak/1.106.0 (build e852934)", date="2025-02-12T12:32:05.261Z") @Stability(Stable) public interface NodejsFunctionProps extends software.amazon.jsii.JsiiSerializable, FunctionOptions
Properties for a NodejsFunction.

Example:

 NodejsFunction.Builder.create(this, "my-handler")
         .bundling(BundlingOptions.builder()
                 .minify(true) // minify code, defaults to false
                 .sourceMap(true) // include source map, defaults to false
                 .sourceMapMode(SourceMapMode.INLINE) // defaults to SourceMapMode.DEFAULT
                 .sourcesContent(false) // do not include original source into source map, defaults to true
                 .target("es2020") // target environment for the generated JavaScript code
                 .loader(Map.of( // Use the 'dataurl' loader for '.png' files
                         ".png", "dataurl"))
                 .define(Map.of( // Replace strings during build time
                         "process.env.API_KEY", JSON.stringify("xxx-xxxx-xxx"),
                         "process.env.PRODUCTION", JSON.stringify(true),
                         "process.env.NUMBER", JSON.stringify(123)))
                 .logLevel(LogLevel.ERROR) // defaults to LogLevel.WARNING
                 .keepNames(true) // defaults to false
                 .tsconfig("custom-tsconfig.json") // use custom-tsconfig.json instead of default,
                 .metafile(true) // include meta file, defaults to false
                 .banner("/* comments */") // requires esbuild >= 0.9.0, defaults to none
                 .footer("/* comments */") // requires esbuild >= 0.9.0, defaults to none
                 .charset(Charset.UTF8) // do not escape non-ASCII characters, defaults to Charset.ASCII
                 .format(OutputFormat.ESM) // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js >= 14)
                 .mainFields(List.of("module", "main")) // prefer ECMAScript versions of dependencies
                 .inject(List.of("./my-shim.js", "./other-shim.js")) // allows to automatically replace a global variable with an import from another file
                 .esbuildArgs(Map.of( // Pass additional arguments to esbuild
                         "--log-limit", "0",
                         "--splitting", true))
                 .build())
         .build();
 
  • Method Details

    • getAwsSdkConnectionReuse

      @Stability(Stable) @Nullable default Boolean getAwsSdkConnectionReuse()
      The AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable does not exist in the AWS SDK for JavaScript v3.

      This prop will be deprecated when the Lambda Node16 runtime is deprecated on June 12, 2024. See https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtime-support-policy

      Info for Node 16 runtimes / SDK v2 users:

      Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript v2.

      This sets the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to 1.

      Default: - false (obsolete) for runtimes >= Node 18, true for runtimes invalid input: '<'= Node 16.

      See Also:
    • getBundling

      @Stability(Stable) @Nullable default BundlingOptions getBundling()
      Bundling options.

      Default: - use default bundling options: no minify, no sourcemap, all modules are bundled.

    • getCode

      @Stability(Stable) @Nullable default Code getCode()
      The code that will be deployed to the Lambda Handler.

      If included, then properties related to bundling of the code are ignored.

      • If the code field is specified, then you must include the handler property.

      Default: - the code is bundled by esbuild

    • getDepsLockFilePath

      @Stability(Stable) @Nullable default String getDepsLockFilePath()
      The path to the dependencies lock file (yarn.lock, pnpm-lock.yaml, bun.lockb or package-lock.json).

      This will be used as the source for the volume mounted in the Docker container.

      Modules specified in nodeModules will be installed using the right installer (yarn, pnpm, bun or npm) along with this lock file.

      Default: - the path is found by walking up parent directories searching for a `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb` or `package-lock.json` file

    • getEntry

      @Stability(Stable) @Nullable default String getEntry()
      Path to the entry file (JavaScript or TypeScript).

      Default: - Derived from the name of the defining file and the construct's id. If the `NodejsFunction` is defined in `stack.ts` with `my-handler` as id (`new NodejsFunction(this, 'my-handler')`), the construct will look at `stack.my-handler.ts` and `stack.my-handler.js`.

    • getHandler

      @Stability(Stable) @Nullable default String getHandler()
      The name of the exported handler in the entry file.

      • If the code property is supplied, then you must include the handler property. The handler should be the name of the file that contains the exported handler and the function that should be called when the AWS Lambda is invoked. For example, if you had a file called myLambda.js and the function to be invoked was myHandler, then you should input handler property as myLambda.myHandler.
      • If the code property is not supplied and the handler input does not contain a ., then the handler is prefixed with index. (index period). Otherwise, the handler property is not modified.

      Default: handler

    • getProjectRoot

      @Stability(Stable) @Nullable default String getProjectRoot()
      The path to the directory containing project config files (package.json or tsconfig.json).

      Default: - the directory containing the `depsLockFilePath`

    • getRuntime

      @Stability(Stable) @Nullable default Runtime getRuntime()
      The runtime environment.

      Only runtimes of the Node.js family are supported.

      Default: `Runtime.NODEJS_LATEST` if the `@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion` feature flag is enabled, otherwise `Runtime.NODEJS_16_X`

    • builder

      @Stability(Stable) static NodejsFunctionProps.Builder builder()
      Returns:
      a NodejsFunctionProps.Builder of NodejsFunctionProps