# WebFunctionAssetOptions

Options common to the asset-based factories.

The asset is a staging copy in the CDK asset bucket; the function serves the object the copy
writes to the destination bucket. So `readers` and `deployTime` apply to that staged object
only — read access to the code the function runs is granted on the destination bucket.

Extends: [AssetOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_s3_assets.AssetOptions.html)

- Source: [`aws-lambda/lib/webfunction-code.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/webfunction-code.ts#L286)
- Type last changed: v2.276.0 · 10 Nov 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_kms as interfaces_kms } from 'aws-cdk-lib/interfaces';
import { aws_logs as interfaces_logs } from 'aws-cdk-lib/interfaces';

declare const dockerImage: cdk.DockerImage;
declare const grantable: iam.IGrantable;
declare const keyRef: interfaces_kms.IKeyRef;
declare const localBundling: cdk.ILocalBundling;
declare const logGroupRef: interfaces_logs.ILogGroupRef;
declare const role: iam.Role;
declare const securityGroup: ec2.SecurityGroup;
declare const subnet: ec2.Subnet;
declare const subnetFilter: ec2.SubnetFilter;
declare const vpc: ec2.Vpc;
const webFunctionAssetOptions: lambda.WebFunctionAssetOptions = {
  assetHash: 'assetHash',
  assetHashType: cdk.AssetHashType.SOURCE,
  bundling: {
    image: dockerImage,

    // the properties below are optional
    bundlingFileAccess: cdk.BundlingFileAccess.VOLUME_COPY,
    command: ['command'],
    entrypoint: ['entrypoint'],
    environment: {
      environmentKey: 'environment',
    },
    local: localBundling,
    network: 'network',
    outputType: cdk.BundlingOutput.ARCHIVED,
    platform: 'platform',
    securityOpt: 'securityOpt',
    user: 'user',
    volumes: [{
      containerPath: 'containerPath',
      hostPath: 'hostPath',

      // the properties below are optional
      consistency: cdk.DockerVolumeConsistency.CONSISTENT,
    }],
    volumesFrom: ['volumesFrom'],
    workingDirectory: 'workingDirectory',
  },
  copyOptions: {
    logGroup: logGroupRef,
    role: role,
    securityGroups: [securityGroup],
    vpc: vpc,
    vpcSubnets: {
      availabilityZones: ['availabilityZones'],
      onePerAz: false,
      subnetFilters: [subnetFilter],
      subnetGroupName: 'subnetGroupName',
      subnets: [subnet],
      subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
    },
  },
  deployTime: false,
  displayName: 'displayName',
  exclude: ['exclude'],
  followSymlinks: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
  readers: [grantable],
  sourceKMSKey: keyRef,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_iam as iam
from aws_cdk import aws_lambda as lambda_
from aws_cdk.interfaces import aws_kms as interfaces_kms
from aws_cdk.interfaces import aws_logs as interfaces_logs

# docker_image: cdk.DockerImage
# grantable: iam.IGrantable
# key_ref: interfaces_kms.IKeyRef
# local_bundling: cdk.ILocalBundling
# log_group_ref: interfaces_logs.ILogGroupRef
# role: iam.Role
# security_group: ec2.SecurityGroup
# subnet: ec2.Subnet
# subnet_filter: ec2.SubnetFilter
# vpc: ec2.Vpc

web_function_asset_options = lambda.WebFunctionAssetOptions(
    asset_hash="assetHash",
    asset_hash_type=cdk.AssetHashType.SOURCE,
    bundling=cdk.BundlingOptions(
        image=docker_image,

        # the properties below are optional
        bundling_file_access=cdk.BundlingFileAccess.VOLUME_COPY,
        command=["command"],
        entrypoint=["entrypoint"],
        environment={
            "environment_key": "environment"
        },
        local=local_bundling,
        network="network",
        output_type=cdk.BundlingOutput.ARCHIVED,
        platform="platform",
        security_opt="securityOpt",
        user="user",
        volumes=[cdk.DockerVolume(
            container_path="containerPath",
            host_path="hostPath",

            # the properties below are optional
            consistency=cdk.DockerVolumeConsistency.CONSISTENT
        )],
        volumes_from=["volumesFrom"],
        working_directory="workingDirectory"
    ),
    copy_options=lambda.WebFunctionCodeCopyOptions(
        log_group=log_group_ref,
        role=role,
        security_groups=[security_group],
        vpc=vpc,
        vpc_subnets=ec2.SubnetSelection(
            availability_zones=["availabilityZones"],
            one_per_az=False,
            subnet_filters=[subnet_filter],
            subnet_group_name="subnetGroupName",
            subnets=[subnet],
            subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
        )
    ),
    deploy_time=False,
    display_name="displayName",
    exclude=["exclude"],
    follow_symlinks=cdk.SymlinkFollowMode.NEVER,
    ignore_mode=cdk.IgnoreMode.GLOB,
    readers=[grantable],
    source_kms_key=key_ref
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.interfaces.kms.*;
import software.amazon.awscdk.interfaces.logs.*;

DockerImage dockerImage;
IGrantable grantable;
IKeyRef keyRef;
ILocalBundling localBundling;
ILogGroupRef logGroupRef;
Role role;
SecurityGroup securityGroup;
Subnet subnet;
SubnetFilter subnetFilter;
Vpc vpc;

WebFunctionAssetOptions webFunctionAssetOptions = WebFunctionAssetOptions.builder()
        .assetHash("assetHash")
        .assetHashType(AssetHashType.SOURCE)
        .bundling(BundlingOptions.builder()
                .image(dockerImage)

                // the properties below are optional
                .bundlingFileAccess(BundlingFileAccess.VOLUME_COPY)
                .command(List.of("command"))
                .entrypoint(List.of("entrypoint"))
                .environment(Map.of(
                        "environmentKey", "environment"))
                .local(localBundling)
                .network("network")
                .outputType(BundlingOutput.ARCHIVED)
                .platform("platform")
                .securityOpt("securityOpt")
                .user("user")
                .volumes(List.of(DockerVolume.builder()
                        .containerPath("containerPath")
                        .hostPath("hostPath")

                        // the properties below are optional
                        .consistency(DockerVolumeConsistency.CONSISTENT)
                        .build()))
                .volumesFrom(List.of("volumesFrom"))
                .workingDirectory("workingDirectory")
                .build())
        .copyOptions(WebFunctionCodeCopyOptions.builder()
                .logGroup(logGroupRef)
                .role(role)
                .securityGroups(List.of(securityGroup))
                .vpc(vpc)
                .vpcSubnets(SubnetSelection.builder()
                        .availabilityZones(List.of("availabilityZones"))
                        .onePerAz(false)
                        .subnetFilters(List.of(subnetFilter))
                        .subnetGroupName("subnetGroupName")
                        .subnets(List.of(subnet))
                        .subnetType(SubnetType.PRIVATE_ISOLATED)
                        .build())
                .build())
        .deployTime(false)
        .displayName("displayName")
        .exclude(List.of("exclude"))
        .followSymlinks(SymlinkFollowMode.NEVER)
        .ignoreMode(IgnoreMode.GLOB)
        .readers(List.of(grantable))
        .sourceKMSKey(keyRef)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK.Interfaces.KMS;
using Amazon.CDK.Interfaces.Logs;

DockerImage dockerImage;
IGrantable grantable;
IKeyRef keyRef;
ILocalBundling localBundling;
ILogGroupRef logGroupRef;
Role role;
SecurityGroup securityGroup;
Subnet subnet;
SubnetFilter subnetFilter;
Vpc vpc;

var webFunctionAssetOptions = new WebFunctionAssetOptions {
    AssetHash = "assetHash",
    AssetHashType = AssetHashType.SOURCE,
    Bundling = new BundlingOptions {
        Image = dockerImage,

        // the properties below are optional
        BundlingFileAccess = BundlingFileAccess.VOLUME_COPY,
        Command = new [] { "command" },
        Entrypoint = new [] { "entrypoint" },
        Environment = new Dictionary<string, string> {
            { "environmentKey", "environment" }
        },
        Local = localBundling,
        Network = "network",
        OutputType = BundlingOutput.ARCHIVED,
        Platform = "platform",
        SecurityOpt = "securityOpt",
        User = "user",
        Volumes = new [] { new DockerVolume {
            ContainerPath = "containerPath",
            HostPath = "hostPath",

            // the properties below are optional
            Consistency = DockerVolumeConsistency.CONSISTENT
        } },
        VolumesFrom = new [] { "volumesFrom" },
        WorkingDirectory = "workingDirectory"
    },
    CopyOptions = new WebFunctionCodeCopyOptions {
        LogGroup = logGroupRef,
        Role = role,
        SecurityGroups = new [] { securityGroup },
        Vpc = vpc,
        VpcSubnets = new SubnetSelection {
            AvailabilityZones = new [] { "availabilityZones" },
            OnePerAz = false,
            SubnetFilters = new [] { subnetFilter },
            SubnetGroupName = "subnetGroupName",
            Subnets = new [] { subnet },
            SubnetType = SubnetType.PRIVATE_ISOLATED
        }
    },
    DeployTime = false,
    DisplayName = "displayName",
    Exclude = new [] { "exclude" },
    FollowSymlinks = SymlinkFollowMode.NEVER,
    IgnoreMode = IgnoreMode.GLOB,
    Readers = new [] { grantable },
    SourceKMSKey = keyRef
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var dockerImage DockerImage
var grantable IGrantable
var keyRef IKeyRef
var localBundling ILocalBundling
var logGroupRef ILogGroupRef
var role Role
var securityGroup SecurityGroup
var subnet Subnet
var subnetFilter SubnetFilter
var vpc Vpc

webFunctionAssetOptions := &WebFunctionAssetOptions{
	AssetHash: jsii.String("assetHash"),
	AssetHashType: cdk.AssetHashType_SOURCE,
	Bundling: &BundlingOptions{
		Image: dockerImage,

		// the properties below are optional
		BundlingFileAccess: cdk.BundlingFileAccess_VOLUME_COPY,
		Command: []*string{
			jsii.String("command"),
		},
		Entrypoint: []*string{
			jsii.String("entrypoint"),
		},
		Environment: map[string]*string{
			"environmentKey": jsii.String("environment"),
		},
		Local: localBundling,
		Network: jsii.String("network"),
		OutputType: cdk.BundlingOutput_ARCHIVED,
		Platform: jsii.String("platform"),
		SecurityOpt: jsii.String("securityOpt"),
		User: jsii.String("user"),
		Volumes: []DockerVolume{
			&DockerVolume{
				ContainerPath: jsii.String("containerPath"),
				HostPath: jsii.String("hostPath"),

				// the properties below are optional
				Consistency: cdk.DockerVolumeConsistency_CONSISTENT,
			},
		},
		VolumesFrom: []*string{
			jsii.String("volumesFrom"),
		},
		WorkingDirectory: jsii.String("workingDirectory"),
	},
	CopyOptions: &WebFunctionCodeCopyOptions{
		LogGroup: logGroupRef,
		Role: role,
		SecurityGroups: []ISecurityGroup{
			securityGroup,
		},
		Vpc: vpc,
		VpcSubnets: &SubnetSelection{
			AvailabilityZones: []*string{
				jsii.String("availabilityZones"),
			},
			OnePerAz: jsii.Boolean(false),
			SubnetFilters: []SubnetFilter{
				subnetFilter,
			},
			SubnetGroupName: jsii.String("subnetGroupName"),
			Subnets: []ISubnet{
				subnet,
			},
			SubnetType: awscdk.Aws_ec2.SubnetType_PRIVATE_ISOLATED,
		},
	},
	DeployTime: jsii.Boolean(false),
	DisplayName: jsii.String("displayName"),
	Exclude: []*string{
		jsii.String("exclude"),
	},
	FollowSymlinks: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
	Readers: []IGrantable{
		grantable,
	},
	SourceKMSKey: keyRef,
}
```

## Properties

- `assetHash`: string — Specify a custom hash for this asset.

  **Default:** based on `assetHashType`

  If `assetHashType` is set it must
  be set to `AssetHashType.CUSTOM`. 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.

- `assetHashType`: [AssetHashType](/cdk/api/v2/docs/aws-cdk-lib.AssetHashType.html) — Specifies the type of hash to calculate for this asset.

  **Default:** the default is `AssetHashType.SOURCE`, but if `assetHash` is explicitly specified this value defaults to `AssetHashType.CUSTOM`.

  If `assetHash` is configured, this option must be `undefined` or
  `AssetHashType.CUSTOM`.

- `bundling`: [BundlingOptions](/cdk/api/v2/docs/aws-cdk-lib.BundlingOptions.html) — Bundle the asset by executing a command in a Docker container or a custom bundling provider.

  **Default:** uploaded as-is to S3 if the asset is a regular file or a .zip file, archived into a .zip file and uploaded to S3 otherwise

  The asset path will be mounted at `/asset-input`. The Docker
  container is responsible for putting content at `/asset-output`.
  The content at `/asset-output` will be zipped and used as the
  final asset.

- `copyOptions`: [WebFunctionCodeCopyOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.WebFunctionCodeCopyOptions.html) — Configuration for the custom resource that copies the staged asset into the destination bucket.

  **Default:** the copy runs outside a VPC with a role created for it

  Use this if your organization requires the copy to run in a VPC, or to supply
  your own execution role.

- `deployTime`: boolean = false — Whether or not the asset needs to exist beyond deployment time;

  i.e.
  are copied over to a different location and not needed afterwards.
  Setting this property to true has an impact on the lifecycle of the asset,
  because we will assume that it is safe to delete after the CloudFormation
  deployment succeeds.

  For example, Lambda Function assets are copied over to Lambda during
  deployment. Therefore, it is not necessary to store the asset in S3, so
  we consider those deployTime assets.

- `displayName`: string — A display name for this asset.

  **Default:** Stack-relative construct path

  If supplied, the display name will be used in locations where the asset
  identifier is printed, like in the CLI progress information. If the same
  asset is added multiple times, the display name of the first occurrence is
  used.

  The default is the construct path of the Asset construct, with respect to
  the enclosing stack. If the asset is produced by a construct helper
  function (such as `lambda.Code.fromAsset()`), this will look like
  `MyFunction/Code`.

  We use the stack-relative construct path so that in the common case where
  you have multiple stacks with the same asset, we won't show something like
  `/MyBetaStack/MyFunction/Code` when you are actually deploying to
  production.

- `exclude`: string[] — File paths matching the patterns will be excluded.

  **Default:** nothing is excluded

  See `ignoreMode` to set the matching behavior.
  Has no effect on Assets bundled using the `bundling` property.

- `followSymlinks`: [SymlinkFollowMode](/cdk/api/v2/docs/aws-cdk-lib.SymlinkFollowMode.html) = SymlinkFollowMode.NEVER — A strategy for how to handle symlinks.

- `ignoreMode`: [IgnoreMode](/cdk/api/v2/docs/aws-cdk-lib.IgnoreMode.html) = IgnoreMode.GLOB — The ignore behavior to use for `exclude` patterns.

- `readers`: [IGrantable](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html)[] — A list of principals that should be able to read this asset from S3.

  **Default:** No principals that can read file asset.

  You can use `asset.grantRead(principal)` to grant read permissions later.

- `sourceKMSKey`: [IKeyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_kms.IKeyRef.html) — The ARN of the KMS key used to encrypt the handler code.

  **Default:** the default server-side encryption with Amazon S3 managed keys(SSE-S3) key will be used.
