Skip to content
v2.278.0

BundlingOptions Struct ​

Bundling options.

Example ​

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
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
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();
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"
});
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 ​

bundlingFileAccessoptionalBundlingFileAccessbundling_file_accessoptionalBundlingFileAccessbundlingFileAccessoptionalBundlingFileAccessBundlingFileAccessoptionalBundlingFileAccessBundlingFileAccessoptionalBundlingFileAccess = 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.
commandoptionalstring[]commandoptionaltyping.List[str]commandoptionalList<String>Commandoptionalstring[]Commandoptional*[]*string #
The command to run in the Docker container.

Default: run the command defined in the image

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

entrypointoptionalstring[]entrypointoptionaltyping.List[str]entrypointoptionalList<String>Entrypointoptionalstring[]Entrypointoptional*[]*string #
The entrypoint to run in the Docker container.

Default: run the entrypoint defined in the image

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

environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[string]*string #
The environment variables to pass to the Docker container.

Default: no environment variables.

The Docker image where the command will run.
localoptionalILocalBundlinglocaloptionalILocalBundlinglocaloptionalILocalBundlingLocaloptionalILocalBundlingLocaloptionalILocalBundling #
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.

networkoptionalstringnetworkoptionalstrnetworkoptionalStringNetworkoptionalstringNetworkoptional*string #

Default: no networking options

outputTypeoptionalBundlingOutputoutput_typeoptionalBundlingOutputoutputTypeoptionalBundlingOutputOutputTypeoptionalBundlingOutputOutputTypeoptionalBundlingOutput = BundlingOutput.AUTO_DISCOVER #
The type of output that this bundling operation is producing.
platformoptionalstringplatformoptionalstrplatformoptionalStringPlatformoptionalstringPlatformoptional*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.

securityOptoptionalstringsecurity_optoptionalstrsecurityOptoptionalStringSecurityOptoptionalstringSecurityOptoptional*string #
Security configuration when running the docker container.

Default: no security options

useroptionalstringuseroptionalstruseroptionalStringUseroptionalstringUseroptional*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

volumesoptionalDockerVolume[]volumesoptionaltyping.List[DockerVolume]volumesoptionalList<DockerVolume>VolumesoptionalDockerVolume[]Volumesoptional*[]DockerVolume #
Additional Docker volumes to mount.

Default: no additional volumes are mounted

volumesFromoptionalstring[]volumes_fromoptionaltyping.List[str]volumesFromoptionalList<String>VolumesFromoptionalstring[]VolumesFromoptional*[]*string #
Where to mount the specified volumes from.

Default: no containers are specified to mount volumes from

workingDirectoryoptionalstringworking_directoryoptionalstrworkingDirectoryoptionalStringWorkingDirectoryoptionalstringWorkingDirectoryoptional*string = /asset-input #
Working directory inside the Docker container.