# BucketDeployment

`BucketDeployment` populates an S3 bucket with the contents of .zip files from other S3 buckets or from local disk.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › BucketDeployment
Implements: [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html)
Superclass of: [DeployTimeSubstitutedFile](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.DeployTimeSubstitutedFile.html)

- Source: [`aws-s3-deployment/lib/bucket-deployment.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.ts#L318)
- Type last changed: v2.269.0 · 10 Sep 2026

## Example

TypeScript:

```ts
declare const destinationBucket: s3.Bucket;

const deployment = new s3deploy.BucketDeployment(this, 'DeployFiles', {
  sources: [s3deploy.Source.asset(path.join(__dirname, 'source-files'))],
  destinationBucket,
});

deployment.handlerRole.addToPolicy(
  new iam.PolicyStatement({
    actions: ['kms:Decrypt', 'kms:DescribeKey'],
    effect: iam.Effect.ALLOW,
    resources: ['<encryption key ARN>'],
  }),
);
```

Python:

```python
# destination_bucket: s3.Bucket

deployment = s3deploy.BucketDeployment(self, "DeployFiles",
    sources=[s3deploy.Source.asset(path.join(__dirname, "source-files"))],
    destination_bucket=destination_bucket
)

deployment.handler_role.add_to_policy(
    iam.PolicyStatement(
        actions=["kms:Decrypt", "kms:DescribeKey"],
        effect=iam.Effect.ALLOW,
        resources=["<encryption key ARN>"]
    ))
```

Java:

```java
Bucket destinationBucket;

BucketDeployment deployment = BucketDeployment.Builder.create(this, "DeployFiles")
        .sources(List.of(Source.asset(join(__dirname, "source-files"))))
        .destinationBucket(destinationBucket)
        .build();

deployment.handlerRole.addToPolicy(
PolicyStatement.Builder.create()
        .actions(List.of("kms:Decrypt", "kms:DescribeKey"))
        .effect(Effect.ALLOW)
        .resources(List.of("<encryption key ARN>"))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Bucket destinationBucket;

var deployment = new BucketDeployment(this, "DeployFiles", new BucketDeploymentProps {
    Sources = new [] { Source.Asset(Join(__dirname, "source-files")) },
    DestinationBucket = destinationBucket
});

deployment.HandlerRole.AddToPolicy(
new PolicyStatement(new PolicyStatementProps {
    Actions = new [] { "kms:Decrypt", "kms:DescribeKey" },
    Effect = Effect.ALLOW,
    Resources = new [] { "<encryption key ARN>" }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var destinationBucket Bucket

deployment := s3deploy.NewBucketDeployment(this, jsii.String("DeployFiles"), &BucketDeploymentProps{
	Sources: []ISource{
		s3deploy.Source_Asset(path.join(__dirname, jsii.String("source-files"))),
	},
	DestinationBucket: DestinationBucket,
})

deployment.HandlerRole.AddToPolicy(
iam.NewPolicyStatement(&PolicyStatementProps{
	Actions: []*string{
		jsii.String("kms:Decrypt"),
		jsii.String("kms:DescribeKey"),
	},
	Effect: iam.Effect_ALLOW,
	Resources: []*string{
		jsii.String("<encryption key ARN>"),
	},
}))
```

## Initializer

TypeScript:

```ts
new BucketDeployment(scope: Construct, id: string, props: BucketDeploymentProps)
```

Python:

```python
BucketDeployment(scope: Construct, id: str, props: BucketDeploymentProps)
```

Java:

```java
new BucketDeployment(Construct scope, String id, BucketDeploymentProps props)
```

C# / .NET:

```csharp
new BucketDeployment(Construct scope, string id, BucketDeploymentProps props)
```

Golang:

```go
NewBucketDeployment(Scope Construct, Id *string, Props BucketDeploymentProps)
```

## Construct Props

- `accessControl`: [BucketAccessControl](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketAccessControl.html) — System-defined x-amz-acl metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `cacheControl`: [CacheControl](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.CacheControl.html)[] — System-defined cache-control metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `contentDisposition`: string — System-defined cache-disposition metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `contentEncoding`: string — System-defined content-encoding metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `contentLanguage`: string — System-defined content-language metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `contentType`: string — System-defined content-type metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `destinationBucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) (required) — The S3 bucket to sync the contents of the zip file to.

- `destinationKeyPrefix`: string — Key prefix in the destination bucket. Must be <=104 characters.

  **Default:** "/" (unzip to root of the destination bucket)

  If it's set with prune: true, it will only prune files with the prefix.

  We recommend to always configure the `destinationKeyPrefix` property. This will prevent the deployment
  from accidentally deleting data that wasn't uploaded by it.

- `distribution`: [IDistributionRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IDistributionRef.html) — The CloudFront distribution using the destination bucket as an origin.

  **Default:** No invalidation occurs

  Files in the distribution's edge caches will be invalidated after
  files are uploaded to the destination bucket.

- `distributionPaths`: string[] — The file paths to invalidate in the CloudFront distribution.

  **Default:** All files under the destination bucket key prefix will be invalidated.

- `ephemeralStorageSize`: [Size](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The size of the AWS Lambda function’s /tmp directory in MiB.

  **Default:** 512 MiB

- `exclude`: string[] — If this is set, matching files or objects will be excluded from the deployment's sync command.

  **Default:** No exclude filters are used

  This can be used to exclude a file from being pruned in the destination bucket.

  If you want to just exclude files from the deployment package (which excludes these files
  evaluated when invalidating the asset), you should leverage the `exclude` property of
  `AssetOptions` when defining your source.

- `expires`: [Expiration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Expiration.html) — System-defined expires metadata to be set on all objects in the deployment.

  **Default:** The objects in the distribution will not expire.

- `extract`: boolean = true — If this is set, the zip file will be synced to the destination S3 bucket and extracted.

  If false, the file will remain zipped in the destination bucket.

- `include`: string[] — If this is set, matching files or objects will be included with the deployment's sync command.

  **Default:** No include filters are used and all files are included with the sync command

  Since all files from the deployment package are included by default, this property
  is usually leveraged alongside an `exclude` filter.

- `logGroup`: [ILogGroupRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_logs.ILogGroupRef.html) — The Log Group used for logging of events emitted by the custom resource's lambda function.

  **Default:** a default log group created by AWS Lambda

  Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
  If you are deploying to another type of region, please check regional availability first.

- `logRetention`: [RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html) = logs.RetentionDays.INFINITE — The number of days that the lambda function's log events are kept in CloudWatch Logs.

  This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
  `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.

- `memoryLimit`: number = 1024 — The amount of memory (in MiB) to allocate to the AWS Lambda function which replicates the files from the CDK bucket to the destination bucket.

  If you are deploying large files, you will need to increase this number
  accordingly.

- `metadata`: { [key: string]: string } — User-defined object metadata to be set on all objects in the deployment.

  **Default:** No user metadata is set

- `outputObjectKeys`: boolean = true — If set to false, the custom resource will not send back the SourceObjectKeys.

  This is useful when you are facing the error `Response object is too long`

  See https://github.com/aws/aws-cdk/issues/28579

- `prune`: boolean = true — By default, files in the destination bucket that don't exist in the source will be deleted when the BucketDeployment resource is created or updated.

  If this is set to false, files in the destination bucket that
  do not exist in the asset, will NOT be deleted during deployment (create/update).

- `retainOnDelete`: boolean — If this is set to "false", the destination files will be deleted when the resource is deleted or the destination is updated.

  **Default:** true - when resource is deleted/updated, files are retained

  NOTICE: Configuring this to "false" might have operational implications. Please
  visit to the package documentation referred below to make sure you fully understand those implications.

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — Execution role associated with this function.

  **Default:** A role is automatically created

- `securityGroups`: [ISecurityGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The list of security groups to associate with the lambda handlers network interfaces.

  **Default:** undefined - If the function is placed within a VPC and a security group is not specified a dedicated security group will be created for this function.

  Only used if 'vpc' is supplied.

- `serverSideEncryption`: [ServerSideEncryption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.ServerSideEncryption.html) — System-defined x-amz-server-side-encryption metadata to be set on all objects in the deployment.

  **Default:** Server side encryption is not used.

- `serverSideEncryptionAwsKmsKeyId`: string — System-defined x-amz-server-side-encryption-aws-kms-key-id metadata to be set on all objects in the deployment.

  **Default:** Not set.

- `serverSideEncryptionCustomerAlgorithm`: string — System-defined x-amz-server-side-encryption-customer-algorithm metadata to be set on all objects in the deployment.

  **Default:** Not set.

  Warning: This is not a useful parameter until this bug is fixed: https://github.com/aws/aws-cdk/issues/6080

- `signContent`: boolean — If set to true, uploads will precompute the value of `x-amz-content-sha256` and include it in the signed S3 request headers.

  **Default:** `x-amz-content-sha256` will not be computed

- `sources`: [ISource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.ISource.html)[] (required) — The sources from which to deploy the contents of this bucket.

- `storageClass`: [StorageClass](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.StorageClass.html) — System-defined x-amz-storage-class metadata to be set on all objects in the deployment.

  **Default:** Default storage-class for the bucket is used.

- `useEfs`: boolean — Mount an EFS file system.

  **Default:** No EFS. Lambda has access only to 512MB of disk space.

  Enable this if your assets are large and you encounter disk space errors.
  Enabling this option will require a VPC to be specified.

- `vpc`: [IVpc](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) = None — The VPC network to place the deployment lambda handler in.

  This is required if `useEfs` is set.

- `vpcSubnets`: [SubnetSelection](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Where in the VPC to place the deployment lambda handler.

  **Default:** the Vpc default strategy if not specified

  Only used if 'vpc' is supplied.

- `waitForDistributionInvalidation`: boolean = true — In case of using a cloudfront distribution, if this property is set to false then the custom resource will not wait and verify for Cloudfront invalidation to complete.

  This may speed up deployment and avoid
  intermittent Cloudfront issues. However, this is risky and not recommended as cache invalidation
  can silently fail.

- `websiteRedirectLocation`: string — System-defined x-amz-website-redirect-location metadata to be set on all objects in the deployment.

  **Default:** No website redirection.

## Properties

- `deployedBucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — The bucket after the deployment.

  If you want to reference the destination bucket in another construct and make sure the
  bucket deployment has happened before the next operation is started, pass the other construct
  a reference to `deployment.deployedBucket`.

  Note that this only returns an immutable reference to the destination bucket.
  If sequenced access to the original destination bucket is required, you may add a dependency
  on the bucket deployment instead: `otherResource.node.addDependency(deployment)`

- `handlerRole`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — Execution role of the Lambda function behind the custom CloudFormation resource of type `Custom::CDKBucketDeployment`.

- `node`: [Node](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `objectKeys`: string[] — The object keys for the sources deployed to the S3 bucket.

  This returns a list of tokenized object keys for source files that are deployed to the bucket.

  This can be useful when using `BucketDeployment` with `extract` set to `false` and you need to reference
  the object key that resides in the bucket for that zip source file somewhere else in your CDK
  application, such as in a CFN output.

  For example, use `Fn.select(0, myBucketDeployment.objectKeys)` to reference the object key of the
  first source file in your bucket deployment.

- `objectVersionIds`: string[] — The S3 version IDs of the objects deployed to the destination bucket.

  Returns a list of tokenized version IDs, positionally matching `objectKeys`: the version ID at
  a given index corresponds to the object key at the same index.

  This is useful when a consumer must reference a specific, immutable version of a deployed
  object — for example a Lambda function that references its code in S3 by version rather than
  copying it.

  Requires versioning to be enabled on the destination bucket; otherwise the returned version IDs
  will be empty strings. Only supported with `extract` set to `false`, where each source zip maps
  1:1 to a destination object. Reading this accessor with `extract` set to `true` (the default)
  throws. It also requires `outputObjectKeys` to remain enabled (the default), since the returned
  list is defined to be positionally aligned with `objectKeys`; reading it with
  `outputObjectKeys` set to `false` throws.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

## Methods

- `addSource(source: ISource): void` — Add an additional source to the bucket deployment.

  ```ts
  declare const websiteBucket: s3.IBucket;
  const deployment = new s3deploy.BucketDeployment(this, 'Deployment', {
    sources: [s3deploy.Source.asset('./website-dist')],
    destinationBucket: websiteBucket,
  });

  deployment.addSource(s3deploy.Source.asset('./another-asset'));
  ```

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
