# BundlingOptions

Bundling options.

Used as argument in: [ILocalBundling.tryBundle](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.ILocalBundling.html#trybundle)

- Source: [`core/lib/bundling.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/core/lib/bundling.ts#L34)
- Type last changed: v2.88.0 · 20 Jul 2023

## Example

TypeScript:

```ts
new lambda.Function(this, 'JavaFunction', {
  code: lambda.Code.fromAsset(path.join(__dirname, 'my-java-handler'), {
    bundling: {
      image: DockerImage.fromRegistry('public.ecr.aws/sam/build-java21:1.153'), // example: the last image with Gradle 8.x
      command: ['bash', '-c', 'gradle build && cp build/distributions/*.zip /asset-output/'], // adjust to your build
    },
  }),
  runtime: lambda.Runtime.JAVA_21,
  handler: 'com.example.Handler::handleRequest',
});
```

Python:

```python
from aws_cdk import BundlingOptions
lambda_.Function(self, "JavaFunction",
    code=lambda_.Code.from_asset(path.join(__dirname, "my-java-handler"),
        bundling=BundlingOptions(
            image=DockerImage.from_registry("public.ecr.aws/sam/build-java21:1.153"),  # example: the last image with Gradle 8.x
            command=["bash", "-c", "gradle build && cp build/distributions/*.zip /asset-output/"]
        )
    ),
    runtime=lambda_.Runtime.JAVA_21,
    handler="com.example.Handler::handleRequest"
)
```

Java:

```java
Function.Builder.create(this, "JavaFunction")
        .code(Code.fromAsset(join(__dirname, "my-java-handler"), AssetOptions.builder()
                .bundling(BundlingOptions.builder()
                        .image(DockerImage.fromRegistry("public.ecr.aws/sam/build-java21:1.153")) // example: the last image with Gradle 8.x
                        .command(List.of("bash", "-c", "gradle build && cp build/distributions/*.zip /asset-output/"))
                        .build())
                .build()))
        .runtime(Runtime.JAVA_21)
        .handler("com.example.Handler::handleRequest")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
new Function(this, "JavaFunction", new FunctionProps {
    Code = Code.FromAsset(Join(__dirname, "my-java-handler"), new AssetOptions {
        Bundling = new BundlingOptions {
            Image = DockerImage.FromRegistry("public.ecr.aws/sam/build-java21:1.153"),  // example: the last image with Gradle 8.x
            Command = new [] { "bash", "-c", "gradle build && cp build/distributions/*.zip /asset-output/" }
        }
    }),
    Runtime = Runtime.JAVA_21,
    Handler = "com.example.Handler::handleRequest"
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
lambda.NewFunction(this, jsii.String("JavaFunction"), &FunctionProps{
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("my-java-handler")), &AssetOptions{
		Bundling: &BundlingOptions{
			Image: awscdk.DockerImage_FromRegistry(jsii.String("public.ecr.aws/sam/build-java21:1.153")),
			 // example: the last image with Gradle 8.x
			Command: []*string{
				jsii.String("bash"),
				jsii.String("-c"),
				jsii.String("gradle build && cp build/distributions/*.zip /asset-output/"),
			},
		},
	}),
	Runtime: lambda.Runtime_JAVA_21(),
	Handler: jsii.String("com.example.Handler::handleRequest"),
})
```

## Properties

- `bundlingFileAccess`: [BundlingFileAccess](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingFileAccess.html) = BundlingFileAccess.BIND_MOUNT — The access mechanism used to make source files available to the bundling container and to return the bundling output back to the host.

- `command`: string[] — The command to run in the Docker container.

  **Default:** run the command defined in the image

  Example value: `['npm', 'install']`

- `entrypoint`: string[] — The entrypoint to run in the Docker container.

  **Default:** run the entrypoint defined in the image

  Example value: `['/bin/sh', '-c']`

- `environment`: { [key: string]: string } — The environment variables to pass to the Docker container.

  **Default:** no environment variables.

- `image`: [DockerImage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.DockerImage.html) (required) — The Docker image where the command will run.

- `local`: [ILocalBundling](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.ILocalBundling.html) — Local bundling provider.

  **Default:** bundling will only be performed in a Docker container

  The provider implements a method `tryBundle()` which should return `true`
  if local bundling was performed. If `false` is returned, docker bundling
  will be done.

- `network`: string — Docker [Networking options](https://docs.docker.com/engine/reference/commandline/run/#connect-a-container-to-a-network---network).

  **Default:** no networking options

- `outputType`: [BundlingOutput](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingOutput.html) = BundlingOutput.AUTO_DISCOVER — The type of output that this bundling operation is producing.

- `platform`: string — Platform to build for. _Requires Docker Buildx_.

  **Default:** no platform specified (the current machine architecture will be used)

  Specify this property to build images on a specific platform.

- `securityOpt`: string — [Security configuration](https://docs.docker.com/engine/reference/run/#security-configuration) when running the docker container.

  **Default:** no security options

- `user`: string — The user to use when running the Docker container.

  **Default:** uid:gid of the current user or 1000:1000 on Windows

  user | user:group | uid | uid:gid | user:gid | uid:group

- `volumes`: [DockerVolume](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.DockerVolume.html)[] — Additional Docker volumes to mount.

  **Default:** no additional volumes are mounted

- `volumesFrom`: string[] — Where to mount the specified volumes from.

  **Default:** no containers are specified to mount volumes from

- `workingDirectory`: string = /asset-input — Working directory inside the Docker container.
