aws-cdk-lib.aws_s3_deployment.Source

class Source

LanguageType name
.NETAmazon.CDK.AWS.S3.Deployment.Source
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awss3deployment#Source
Javasoftware.amazon.awscdk.services.s3.deployment.Source
Pythonaws_cdk.aws_s3_deployment.Source
TypeScript (source)aws-cdk-lib » aws_s3_deployment » 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.dataJson('config.json', { baz: topic.topicArn })
Source.dataYaml('config.yaml', { baz: topic.topicArn })

Example

declare const websiteBucket: s3.Bucket;

const deployment = new s3deploy.BucketDeployment(this, 'DeployWebsite', {
  sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
  destinationBucket: websiteBucket,
});

new ConstructThatReadsFromTheBucket(this, 'Consumer', {
  // Use 'deployment.deployedBucket' instead of 'websiteBucket' here
  bucket: deployment.deployedBucket,
});

Methods

NameDescription
static asset(path, options?)Uses a local asset as the deployment source.
static bucket(bucket, zipObjectKey)Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents.
static data(objectKey, data)Deploys an object with the specified string contents into the bucket.
static jsonData(objectKey, obj)Deploys an object with the specified JSON object into the bucket.
static yamlData(objectKey, obj)Deploys an object with the specified JSON object formatted as YAML into the bucket.

static asset(path, options?)

public static asset(path: string, options?: AssetOptions): ISource

Parameters

  • path string — The path to a local .zip file or a directory.
  • options AssetOptions

Returns

  • ISource

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.


static bucket(bucket, zipObjectKey)

public static bucket(bucket: IBucket, zipObjectKey: string): ISource

Parameters

  • bucket IBucket — The S3 Bucket.
  • zipObjectKey string — The S3 object key of the zip file with contents.

Returns

  • ISource

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.


static data(objectKey, data)

public static data(objectKey: string, data: string): ISource

Parameters

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

Returns

  • ISource

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.

To store a JSON object use Source.jsonData(). To store YAML content use Source.yamlData().


static jsonData(objectKey, obj)

public static jsonData(objectKey: string, obj: any): ISource

Parameters

  • objectKey string — The destination S3 object key (relative to the root of the S3 deployment).
  • obj any — A JSON object.

Returns

  • ISource

Deploys an object with the specified JSON object into the bucket.

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


static yamlData(objectKey, obj)

public static yamlData(objectKey: string, obj: any): ISource

Parameters

  • objectKey string — The destination S3 object key (relative to the root of the S3 deployment).
  • obj any — A JSON object.

Returns

  • ISource

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.