Show / Hide Table of Contents

Class Source

Specifies bucket deployment source.

Inheritance
object
Source
Namespace: Amazon.CDK.AWS.S3.Deployment
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Source : DeputyBase
Syntax (vb)
Public Class Source Inherits DeputyBase
Remarks

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 })

ExampleMetadata: infused

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

Synopsis

Methods

Asset(string, IAssetOptions?)

Uses a local asset as the deployment source.

Bucket(IBucket, string)

Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents.

Data(string, string, IMarkersConfig?)

Deploys an object with the specified string contents into the bucket.

JsonData(string, object, IJsonProcessingOptions?)

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

YamlData(string, object)

Deploys an object with the specified JSON object formatted as YAML into the bucket.

Methods

Asset(string, IAssetOptions?)

Uses a local asset as the deployment source.

public static ISource Asset(string path, IAssetOptions? options = null)
Parameters
path string

The path to a local .zip file or a directory.

options IAssetOptions

The path to a local .zip file or a directory.

Returns

ISource

Remarks

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

Bucket(IBucket, string)

Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents.

public static ISource Bucket(IBucket bucket, string zipObjectKey)
Parameters
bucket IBucket

The S3 Bucket.

zipObjectKey string

The S3 object key of the zip file with contents.

Returns

ISource

Remarks

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.

Examples
Bucket destinationBucket;

             var sourceBucket = Bucket.FromBucketAttributes(this, "SourceBucket", new BucketAttributes {
                 BucketArn = "arn:aws:s3:::my-source-bucket-name",
                 EncryptionKey = Key.FromKeyArn(this, "SourceBucketEncryptionKey", "arn:aws:kms:us-east-1:123456789012:key/<key-id>")
             });
             var deployment = new BucketDeployment(this, "DeployFiles", new BucketDeploymentProps {
                 Sources = new [] { Source.Bucket(sourceBucket, "source.zip") },
                 DestinationBucket = destinationBucket
             });

Data(string, string, IMarkersConfig?)

Deploys an object with the specified string contents into the bucket.

public static ISource Data(string objectKey, string data, IMarkersConfig? markersConfig = null)
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.

markersConfig IMarkersConfig

The destination S3 object key (relative to the root of the S3 deployment).

Returns

ISource

Remarks

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().

JsonData(string, object, IJsonProcessingOptions?)

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

public static ISource JsonData(string objectKey, object obj, IJsonProcessingOptions? jsonProcessingOptions = null)
Parameters
objectKey string

The destination S3 object key (relative to the root of the S3 deployment).

obj object

A JSON object.

jsonProcessingOptions IJsonProcessingOptions

Options for how to process the JSON object.

Returns

ISource

Remarks

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

YamlData(string, object)

Deploys an object with the specified JSON object formatted as YAML into the bucket.

public static ISource YamlData(string objectKey, object obj)
Parameters
objectKey string

The destination S3 object key (relative to the root of the S3 deployment).

obj object

A JSON object.

Returns

ISource

Remarks

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

Back to top Generated by DocFX