Class Source
Specifies bucket deployment source.
Inheritance
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
Constructors
Source(By |
Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Source(Deputy |
Used by jsii to construct an instance of this class from DeputyProps |
Methods
Asset(String, IAsset |
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) | Deploys an object with the specified string contents into the bucket. |
Json |
Deploys an object with the specified JSON object into the bucket. |
Yaml |
Deploys an object with the specified JSON object formatted as YAML into the bucket. |
Constructors
Source(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Source(ByRefValue reference)
Parameters
- reference Amazon.
JSII. Runtime. Deputy. By Ref Value The Javascript-owned object reference
Source(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Source(DeputyBase.DeputyProps props)
Parameters
- props Amazon.
JSII. Runtime. Deputy. Deputy Base. Deputy Props The deputy props
Methods
Asset(String, IAssetOptions)
Uses a local asset as the deployment source.
public static ISource Asset(string path, IAssetOptions options = null)
Parameters
- path System.
String The path to a local .zip file or a directory.
- options IAsset
Options The path to a local .zip file or a directory.
Returns
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 System.
String The S3 object key of the zip file with contents.
Returns
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)
Deploys an object with the specified string contents into the bucket.
public static ISource Data(string objectKey, string data)
Parameters
- objectKey System.
String The destination S3 object key (relative to the root of the S3 deployment).
- data System.
String The data to be stored in the object.
Returns
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)
Deploys an object with the specified JSON object into the bucket.
public static ISource JsonData(string objectKey, object obj)
Parameters
- objectKey System.
String The destination S3 object key (relative to the root of the S3 deployment).
- obj System.
Object A JSON object.
Returns
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 System.
String The destination S3 object key (relative to the root of the S3 deployment).
- obj System.
Object A JSON object.
Returns
Remarks
The object can include deploy-time values (such as snsTopic.topicArn
) that
will get resolved only during deployment.