# Source

Specifies bucket deployment source.

Usage:

    Source.bucket(bucket, key)
    Source.asset('/local/path/to/directory')
    Source.asset('/local/path/to/a/file.zip')
    Source.data('hello/world/file.txt', 'Hello, world!')
    Source.jsonData('config.json', { baz: topic.topicArn })
    Source.yamlData('config.yaml', { baz: topic.topicArn })

- Source: [`aws-s3-deployment/lib/source.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-s3-deployment/lib/source.ts#L137)
- Type last changed: v2.276.0 · 10 Nov 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>"),
	},
}))
```

## Methods

- `asset(path: string, options?: AssetOptions): ISource` (static) — Uses a local asset as the deployment source.

  If the local asset is a .zip archive, make sure you trust the
  producer of the archive.

  **Parameters**

  - `path` — The path to a local .zip file or a directory.

- `bucket(bucket: IBucket, zipObjectKey: string): ISource` (static) — Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents.

  Make sure you trust the producer of the archive.

  If the `bucket` parameter is an "out-of-app" reference "imported" via static methods such
  as `s3.Bucket.fromBucketName`, be cautious about the bucket's encryption key. In general,
  CDK does not query for additional properties of imported constructs at synthesis time.
  For example, for a bucket created from `s3.Bucket.fromBucketName`, CDK does not know
  its `IBucket.encryptionKey` property, and therefore will NOT give KMS permissions to the
  Lambda execution role of the `BucketDeployment` construct. If you want the
  `kms:Decrypt` and `kms:DescribeKey` permissions on the bucket's encryption key
  to be added automatically, reference the imported bucket via `s3.Bucket.fromBucketAttributes`
  and pass in the `encryptionKey` attribute explicitly.

  **Parameters**

  - `bucket` — The S3 Bucket.
  - `zipObjectKey` — The S3 object key of the zip file with contents.

  ```ts
  declare const destinationBucket: s3.Bucket;
  const sourceBucket = s3.Bucket.fromBucketAttributes(this, 'SourceBucket', {
    bucketArn: 'arn:aws:s3:::my-source-bucket-name',
    encryptionKey: kms.Key.fromKeyArn(
      this,
      'SourceBucketEncryptionKey',
      'arn:aws:kms:us-east-1:123456789012:key/<key-id>'
    ),
  });
  const deployment = new s3deploy.BucketDeployment(this, 'DeployFiles', {
    sources: [s3deploy.Source.bucket(sourceBucket, 'source.zip')],
    destinationBucket,
  });
  ```

- `data(objectKey: string, data: string, markersConfig?: SourceDataOptions): ISource` (static) — Deploys an object with the specified string contents into the bucket.

  The content can include deploy-time values (such as `snsTopic.topicArn`)
  that will get resolved only during deployment.

  The content is treated as an unstructured string, and deploy-time values
  will (mostly) be replaced with a plain string substitution. To store
  structured data, use either `Source.jsonData()` or `Source.yamlData()`.

  ## Default behavior

  Due to CloudFormation behavior, scalars (strings, numbers and booleans) in Token values are
  all treated as strings at deploy time (`"80"`, `"true"`, etc).

  - Scalars are plain-text substituted.
  - Non-scalars (lists, objects) lead to a deployment error

  ## JSON escaping

  JSON escaping can be forced by specifying `{ jsonEscape: true }`. Values
  are substituted as follows:

  - Scalars come in as strings pre-encoded by CloudFormation; they are JSON-encoded, and then substituted without their surrounding quotes.
    - Strings expect to go into a pre-quoted JSON string context (e.g., `Source.data('{"arn": "' + snsTopic.topicArn + '"}')`).
    - Non-strings expect to go into a non-quoted JSON context (e.g., `Source.data('{"port": ' + cluster.port + '}')`).
  - Non-scalars are JSON-encoded and then fully substituted. They expect to go into a non-quoted JSON
    context in the input string (e.g., `Source.data('{"ports": ' + Token.asString(cluster.allPorts) + '}')`).

  **Parameters**

  - `objectKey` — The destination S3 object key (relative to the root of the S3 deployment).
  - `data` — The data to be stored in the object.

- `jsonData(objectKey: string, obj: any, jsonProcessingOptions?: JsonProcessingOptions): ISource` (static) — Deploys an object with the specified JSON object into the bucket.

  The content can include deploy-time values (such as `snsTopic.topicArn`)
  that will get resolved only during deployment.

  Quoting of deploy-time values will be done according to the ostensible
  type of the Token used to represent the deploy-time value.

  - String tokens will be quoted into the JSON string skeleton, and
    deploy-time values will be encoded and substituted without their
    surrounding quotes. Will substitute correctly to working JSON if the
    deploy-time value is a string.
  - Number and list tokens will be encoded and substituted without quotes. Will
    substitute correctly to working JSON if the deploy-time value is a
    number, boolean or list or map.

  Note that due to CloudFormation behavior, scalars inside lists and maps
  will always be converted to strings.

  **Parameters**

  - `objectKey` — The destination S3 object key (relative to the root of the S3 deployment).
  - `obj` — A JSON object.
  - `jsonProcessingOptions` — Options for how to process the JSON object.

- `yamlData(objectKey: string, obj: any): ISource` (static) — Deploys an object with the specified JSON object formatted as YAML into the bucket.

  The object can include deploy-time values (such as `snsTopic.topicArn`) that
  will get resolved only during deployment.

  Quoting of deploy-time values will be done according to the ostensible
  type of the Token used to represent the deploy-time value.

  - String tokens will be unquoted if they are simple strings (basically, identifiers), and quoted
    if they start to look complex.
  - Number and list tokens will be encoded and substituted without quotes. Will
    substitute correctly to working JSON if the deploy-time value is a
    number, boolean or list or map.

  Note that due to CloudFormation behavior, scalars inside lists and maps
  will always be converted to strings.

  **Parameters**

  - `objectKey` — The destination S3 object key (relative to the root of the S3 deployment).
  - `obj` — A JSON object.
