Class BundlingOptions.Builder

java.lang.Object
software.amazon.awscdk.services.lambda.nodejs.BundlingOptions.Builder
All Implemented Interfaces:
software.amazon.jsii.Builder<BundlingOptions>
Enclosing interface:
BundlingOptions

@Stability(Stable) public static final class BundlingOptions.Builder extends Object implements software.amazon.jsii.Builder<BundlingOptions>
A builder for BundlingOptions
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • assetHash

      @Stability(Stable) public BundlingOptions.Builder assetHash(String assetHash)
      Parameters:
      assetHash - Specify a custom hash for this asset. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash.

      NOTE: the hash is used in order to identify a specific revision of the asset, and used for optimizing and caching deployment activities related to this asset such as packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will need to make sure it is updated every time the asset changes, or otherwise it is possible that some deployments will not be invalidated.

      Returns:
      this
    • banner

      @Stability(Stable) public BundlingOptions.Builder banner(String banner)
      Sets the value of BundlingOptions.getBanner()
      Parameters:
      banner - Use this to insert an arbitrary string at the beginning of generated JavaScript files. This is similar to footer which inserts at the end instead of the beginning.

      This is commonly used to insert comments:

      Returns:
      this
    • buildArgs

      @Stability(Stable) public BundlingOptions.Builder buildArgs(Map<String,String> buildArgs)
      Parameters:
      buildArgs - Build arguments to pass when building the bundling image.
      Returns:
      this
    • bundleAwsSdk

      @Stability(Stable) public BundlingOptions.Builder bundleAwsSdk(Boolean bundleAwsSdk)
      Sets the value of
      invalid @link
      BundlingOptions#getBundleAwsSdk
      Parameters:
      bundleAwsSdk - Includes AWS SDK in the bundle asset.
      Returns:
      this
    • bundlingFileAccess

      @Stability(Stable) public BundlingOptions.Builder bundlingFileAccess(BundlingFileAccess bundlingFileAccess)
      Parameters:
      bundlingFileAccess - Which option to use to copy the source files to the docker container and output files back.
      Returns:
      this
    • charset

      @Stability(Stable) public BundlingOptions.Builder charset(Charset charset)
      Parameters:
      charset - The charset to use for esbuild's output. By default esbuild's output is ASCII-only. Any non-ASCII characters are escaped using backslash escape sequences. Using escape sequences makes the generated output slightly bigger, and also makes it harder to read. If you would like for esbuild to print the original characters without using escape sequences, use Charset.UTF8.
      Returns:
      this
    • commandHooks

      @Stability(Stable) public BundlingOptions.Builder commandHooks(ICommandHooks commandHooks)
      Parameters:
      commandHooks - Command hooks.
      Returns:
      this
    • define

      @Stability(Stable) public BundlingOptions.Builder define(Map<String,String> define)
      Sets the value of BundlingOptions.getDefine()
      Parameters:
      define - Replace global identifiers with constant expressions. For example, { 'process.env.DEBUG': 'true' }.

      Another example, { 'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx') }.

      Returns:
      this
    • dockerImage

      @Stability(Stable) public BundlingOptions.Builder dockerImage(DockerImage dockerImage)
      Parameters:
      dockerImage - A custom bundling Docker image. This image should have esbuild installed globally. If you plan to use nodeModules it should also have npm, yarn or pnpm depending on the lock file you're using.

      See https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile for the default image provided by aws-cdk-lib/aws-lambda-nodejs.

      Returns:
      this
    • esbuildArgs

      @Stability(Stable) public BundlingOptions.Builder esbuildArgs(Map<String,? extends Object> esbuildArgs)
      Parameters:
      esbuildArgs - Build arguments to pass into esbuild. For example, to add the --log-limit flag:

                          new NodejsFunction(scope, id, {
                            ...
                            bundling: {
                              esbuildArgs: {
                                "--log-limit": "0",
                              }
                            }
                          });
                          
      Returns:
      this
    • esbuildVersion

      @Stability(Stable) public BundlingOptions.Builder esbuildVersion(String esbuildVersion)
      Parameters:
      esbuildVersion - The version of esbuild to use when running in a Docker container.
      Returns:
      this
    • externalModules

      @Stability(Stable) public BundlingOptions.Builder externalModules(List<String> externalModules)
      Parameters:
      externalModules - A list of modules that should be considered as externals (already available in the runtime).
      Returns:
      this
    • footer

      @Stability(Stable) public BundlingOptions.Builder footer(String footer)
      Sets the value of BundlingOptions.getFooter()
      Parameters:
      footer - Use this to insert an arbitrary string at the end of generated JavaScript files. This is similar to banner which inserts at the beginning instead of the end.

      This is commonly used to insert comments

      Returns:
      this
    • forceDockerBundling

      @Stability(Stable) public BundlingOptions.Builder forceDockerBundling(Boolean forceDockerBundling)
      Parameters:
      forceDockerBundling - Force bundling in a Docker container even if local bundling is possible. This is useful if your function relies on node modules that should be installed (nodeModules) in a Lambda compatible environment.
      Returns:
      this
    • format

      @Stability(Stable) public BundlingOptions.Builder format(OutputFormat format)
      Sets the value of BundlingOptions.getFormat()
      Parameters:
      format - Output format for the generated JavaScript files.
      Returns:
      this
    • inject

      @Stability(Stable) public BundlingOptions.Builder inject(List<String> inject)
      Sets the value of BundlingOptions.getInject()
      Parameters:
      inject - This option allows you to automatically replace a global variable with an import from another file.
      Returns:
      this
    • keepNames

      @Stability(Stable) public BundlingOptions.Builder keepNames(Boolean keepNames)
      Parameters:
      keepNames - Whether to preserve the original name values even in minified code. In JavaScript the name property on functions and classes defaults to a nearby identifier in the source code.

      However, minification renames symbols to reduce code size and bundling sometimes need to rename symbols to avoid collisions. That changes value of the name property for many of these cases. This is usually fine because the name property is normally only used for debugging. However, some frameworks rely on the name property for registration and binding purposes. If this is the case, you can enable this option to preserve the original name values even in minified code.

      Returns:
      this
    • loader

      @Stability(Stable) public BundlingOptions.Builder loader(Map<String,String> loader)
      Sets the value of BundlingOptions.getLoader()
      Parameters:
      loader - Use loaders to change how a given input file is interpreted. Configuring a loader for a given file type lets you load that file type with an import statement or a require call.

      For example, { '.png': 'dataurl' }.

      Returns:
      this
    • logLevel

      @Stability(Stable) public BundlingOptions.Builder logLevel(LogLevel logLevel)
      Parameters:
      logLevel - Log level for esbuild. This is also propagated to the package manager and applies to its specific install command.
      Returns:
      this
    • mainFields

      @Stability(Stable) public BundlingOptions.Builder mainFields(List<String> mainFields)
      Parameters:
      mainFields - How to determine the entry point for modules. Try ['module', 'main'] to default to ES module versions.
      Returns:
      this
    • metafile

      @Stability(Stable) public BundlingOptions.Builder metafile(Boolean metafile)
      Parameters:
      metafile - This option tells esbuild to write out a JSON file relative to output directory with metadata about the build. The metadata in this JSON file follows this schema (specified using TypeScript syntax):

                       {
                         outputs: {
                           [path: string]: {
                             bytes: number
                             inputs: {
                               [path: string]: { bytesInOutput: number }
                             }
                             imports: { path: string }[]
                             exports: string[]
                           }
                         }
                       }
                       

      This data can then be analyzed by other tools. For example, bundle buddy can consume esbuild's metadata format and generates a treemap visualization of the modules in your bundle and how much space each one takes up.

      Returns:
      this
    • minify

      @Stability(Stable) public BundlingOptions.Builder minify(Boolean minify)
      Sets the value of BundlingOptions.getMinify()
      Parameters:
      minify - Whether to minify files when bundling.
      Returns:
      this
    • nodeModules

      @Stability(Stable) public BundlingOptions.Builder nodeModules(List<String> nodeModules)
      Parameters:
      nodeModules - A list of modules that should be installed instead of bundled. Modules are installed in a Lambda compatible environment only when bundling runs in Docker.
      Returns:
      this
    • preCompilation

      @Stability(Stable) public BundlingOptions.Builder preCompilation(Boolean preCompilation)
      Parameters:
      preCompilation - Run compilation using tsc before running file through bundling step. This usually is not required unless you are using new experimental features that are only supported by typescript's tsc compiler. One example of such feature is emitDecoratorMetadata.
      Returns:
      this
    • sourceMap

      @Stability(Stable) public BundlingOptions.Builder sourceMap(Boolean sourceMap)
      Parameters:
      sourceMap - Whether to include source maps when bundling.
      Returns:
      this
    • sourceMapMode

      @Stability(Stable) public BundlingOptions.Builder sourceMapMode(SourceMapMode sourceMapMode)
      Parameters:
      sourceMapMode - Source map mode to be used when bundling.
      Returns:
      this
    • sourcesContent

      @Stability(Stable) public BundlingOptions.Builder sourcesContent(Boolean sourcesContent)
      Parameters:
      sourcesContent - Whether to include original source code in source maps when bundling.
      Returns:
      this
    • target

      @Stability(Stable) public BundlingOptions.Builder target(String target)
      Sets the value of BundlingOptions.getTarget()
      Parameters:
      target - Target environment for the generated JavaScript code.
      Returns:
      this
    • tsconfig

      @Stability(Stable) public BundlingOptions.Builder tsconfig(String tsconfig)
      Parameters:
      tsconfig - Normally the esbuild automatically discovers tsconfig.json files and reads their contents during a build. However, you can also configure a custom tsconfig.json file to use instead.

      This is similar to entry path, you need to provide path to your custom tsconfig.json.

      This can be useful if you need to do multiple builds of the same code with different settings.

      For example, { 'tsconfig': 'path/custom.tsconfig.json' }.

      Returns:
      this
    • command

      @Stability(Stable) public BundlingOptions.Builder command(List<String> command)
      Parameters:
      command - The command to run in the container.
      Returns:
      this
    • entrypoint

      @Stability(Stable) public BundlingOptions.Builder entrypoint(List<String> entrypoint)
      Parameters:
      entrypoint - The entrypoint to run in the container.
      Returns:
      this
    • environment

      @Stability(Stable) public BundlingOptions.Builder environment(Map<String,String> environment)
      Parameters:
      environment - The environment variables to pass to the container.
      Returns:
      this
    • network

      @Stability(Stable) public BundlingOptions.Builder network(String network)
      Parameters:
      network - Docker Networking options.
      Returns:
      this
    • platform

      @Stability(Stable) public BundlingOptions.Builder platform(String platform)
      Parameters:
      platform - Set platform if server is multi-platform capable. Requires Docker Engine API v1.38+. Example value: linux/amd64
      Returns:
      this
    • securityOpt

      @Stability(Stable) public BundlingOptions.Builder securityOpt(String securityOpt)
      Parameters:
      securityOpt - Security configuration when running the docker container.
      Returns:
      this
    • user

      @Stability(Stable) public BundlingOptions.Builder user(String user)
      Sets the value of DockerRunOptions.getUser()
      Parameters:
      user - The user to use when running the container.
      Returns:
      this
    • volumes

      @Stability(Stable) public BundlingOptions.Builder volumes(List<? extends DockerVolume> volumes)
      Parameters:
      volumes - Docker volumes to mount.
      Returns:
      this
    • volumesFrom

      @Stability(Stable) public BundlingOptions.Builder volumesFrom(List<String> volumesFrom)
      Parameters:
      volumesFrom - Where to mount the specified volumes from.
      Returns:
      this
    • workingDirectory

      @Stability(Stable) public BundlingOptions.Builder workingDirectory(String workingDirectory)
      Parameters:
      workingDirectory - Working directory inside the container.
      Returns:
      this
    • build

      @Stability(Stable) public BundlingOptions build()
      Builds the configured instance.
      Specified by:
      build in interface software.amazon.jsii.Builder<BundlingOptions>
      Returns:
      a new instance of BundlingOptions
      Throws:
      NullPointerException - if any required attribute was not provided