Class: AWSCDK::S3Deployment::Source

Inherits:
Jsii::Object
  • Object
show all
Defined in:
s3_deployment/source.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Source

Returns a new instance of Source.

Raises:

  • (NoMethodError)


19
20
21
# File 's3_deployment/source.rb', line 19

def initialize(*args)
  raise NoMethodError, "aws-cdk-lib.aws_s3_deployment.Source does not have a visible constructor; use the provided factory methods"
end

Class Method Details

.asset(path, options = nil) ⇒ AWSCDK::S3Deployment::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.

Parameters:

Returns:



36
37
38
39
40
41
# File 's3_deployment/source.rb', line 36

def self.asset(path, options = nil)
  Jsii::Type.check_type(path, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "path")
  options = options.is_a?(Hash) ? ::AWSCDK::S3Assets::AssetOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfYXNzZXRzLkFzc2V0T3B0aW9ucyJ9")), "options") unless options.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_s3_deployment.Source", "asset", [path, options])
end

.bucket(bucket, zip_object_key) ⇒ AWSCDK::S3Deployment::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.

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 encryption_key attribute explicitly.

Examples:

destination_bucket = nil # AWSCDK::S3::Bucket

source_bucket = AWSCDK::S3::Bucket.from_bucket_attributes(self, "SourceBucket", {
    bucket_arn: "arn:aws:s3:::my-source-bucket-name",
    encryption_key: AWSCDK::KMS::Key.from_key_arn(self, "SourceBucketEncryptionKey", "arn:aws:kms:us-east-1:123456789012:key/<key-id>"),
})
deployment = AWSCDK::S3Deployment::BucketDeployment.new(self, "DeployFiles", {
    sources: [AWSCDK::S3Deployment::Source.bucket(source_bucket, "source.zip")],
    destination_bucket: destination_bucket,
})

Parameters:

  • bucket (AWSCDK::S3::IBucket)

    The S3 Bucket.

  • zip_object_key (String)

    The S3 object key of the zip file with contents.

Returns:



71
72
73
74
75
# File 's3_deployment/source.rb', line 71

def self.bucket(bucket, zip_object_key)
  Jsii::Type.check_type(bucket, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczMuSUJ1Y2tldCJ9")), "bucket")
  Jsii::Type.check_type(zip_object_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "zipObjectKey")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_s3_deployment.Source", "bucket", [bucket, zip_object_key])
end

.data(object_key, data, markers_config = nil) ⇒ AWSCDK::S3Deployment::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().

Parameters:

  • object_key (String)

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

  • data (String)

    The data to be stored in the object.

  • markers_config (AWSCDK::S3Deployment::MarkersConfig, nil) (defaults to: nil)

Returns:



90
91
92
93
94
95
96
# File 's3_deployment/source.rb', line 90

def self.data(object_key, data, markers_config = nil)
  Jsii::Type.check_type(object_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "objectKey")
  Jsii::Type.check_type(data, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "data")
  markers_config = markers_config.is_a?(Hash) ? ::AWSCDK::S3Deployment::MarkersConfig.new(**markers_config.transform_keys(&:to_sym)) : markers_config
  Jsii::Type.check_type(markers_config, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfZGVwbG95bWVudC5NYXJrZXJzQ29uZmlnIn0=")), "markersConfig") unless markers_config.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_s3_deployment.Source", "data", [object_key, data, markers_config])
end

.jsii_overridable_methodsObject



23
24
25
26
# File 's3_deployment/source.rb', line 23

def self.jsii_overridable_methods
  {
  }
end

.json_data(object_key, obj, json_processing_options = nil) ⇒ AWSCDK::S3Deployment::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.

Parameters:

  • object_key (String)

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

  • obj (Object)

    A JSON object.

  • json_processing_options (AWSCDK::S3Deployment::JsonProcessingOptions, nil) (defaults to: nil)

    Options for how to process the JSON object.

Returns:



108
109
110
111
112
113
114
# File 's3_deployment/source.rb', line 108

def self.json_data(object_key, obj, json_processing_options = nil)
  Jsii::Type.check_type(object_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "objectKey")
  Jsii::Type.check_type(obj, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "obj")
  json_processing_options = json_processing_options.is_a?(Hash) ? ::AWSCDK::S3Deployment::JsonProcessingOptions.new(**json_processing_options.transform_keys(&:to_sym)) : json_processing_options
  Jsii::Type.check_type(json_processing_options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfZGVwbG95bWVudC5Kc29uUHJvY2Vzc2luZ09wdGlvbnMifQ==")), "jsonProcessingOptions") unless json_processing_options.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_s3_deployment.Source", "jsonData", [object_key, obj, json_processing_options])
end

.yaml_data(object_key, obj) ⇒ AWSCDK::S3Deployment::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.

Parameters:

  • object_key (String)

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

  • obj (Object)

    A JSON object.

Returns:



124
125
126
127
128
# File 's3_deployment/source.rb', line 124

def self.yaml_data(object_key, obj)
  Jsii::Type.check_type(object_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "objectKey")
  Jsii::Type.check_type(obj, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "obj")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_s3_deployment.Source", "yamlData", [object_key, obj])
end