Class: AWSCDK::AssetStaging

Inherits:
Constructs::Construct
  • Object
show all
Defined in:
asset_staging.rb

Overview

Stages a file or directory from a location on the file system into a staging directory.

This is controlled by the context key 'aws:cdk:asset-staging' and enabled by the CLI by default in order to ensure that when the CDK app exists, all assets are available for deployment. Otherwise, if an app references assets in temporary locations, those will not be available when it exists (see https://github.com/aws/aws-cdk/issues/1716).

The staged_path property is a stringified token that represents the location of the file or directory after staging. It will be resolved only during the "prepare" stage and may be either the original path or the staged path depending on the context setting.

The file/directory are staged based on their content hash (fingerprint). This means that only if content was changed, copy will happen.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, id, props) ⇒ AssetStaging

Returns a new instance of AssetStaging.

Parameters:



25
26
27
28
29
30
31
# File 'asset_staging.rb', line 25

def initialize(scope, id, props)
  props = props.is_a?(Hash) ? ::AWSCDK::AssetStagingProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5Bc3NldFN0YWdpbmdQcm9wcyJ9")), "props")
  Jsii::Object.instance_method(:initialize).bind(self).call(scope, id, props)
end

Class Method Details

.BUNDLING_INPUT_DIRString

The directory inside the bundling container into which the asset sources will be mounted.

Returns:

  • (String)


64
65
66
# File 'asset_staging.rb', line 64

def self.BUNDLING_INPUT_DIR()
  Jsii::Kernel.instance.get_static("aws-cdk-lib.AssetStaging", "BUNDLING_INPUT_DIR")
end

.BUNDLING_OUTPUT_DIRString

The directory inside the bundling container into which the bundled output should be written.

Returns:

  • (String)


71
72
73
# File 'asset_staging.rb', line 71

def self.BUNDLING_OUTPUT_DIR()
  Jsii::Kernel.instance.get_static("aws-cdk-lib.AssetStaging", "BUNDLING_OUTPUT_DIR")
end

.clear_asset_hash_cachevoid

This method returns an undefined value.

Clears the asset hash cache.



50
51
52
# File 'asset_staging.rb', line 50

def self.clear_asset_hash_cache()
  Jsii::Kernel.instance.call_static("aws-cdk-lib.AssetStaging", "clearAssetHashCache", [])
end

.jsii_overridable_methodsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'asset_staging.rb', line 33

def self.jsii_overridable_methods
  {
    :node => { kind: :property, name: "node", is_optional: false },
    :absolute_staged_path => { kind: :property, name: "absoluteStagedPath", is_optional: false },
    :asset_hash => { kind: :property, name: "assetHash", is_optional: false },
    :is_archive => { kind: :property, name: "isArchive", is_optional: false },
    :packaging => { kind: :property, name: "packaging", is_optional: false },
    :source_path => { kind: :property, name: "sourcePath", is_optional: false },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :with => { kind: :method, name: "with", is_optional: false },
    :relative_staged_path => { kind: :method, name: "relativeStagedPath", is_optional: false },
  }
end

Instance Method Details

#absolute_staged_pathString

Absolute path to the asset data.

If asset staging is disabled, this will just be the source path or a temporary directory used for bundling.

If asset staging is enabled it will be the staged path.

IMPORTANT: If you are going to call add_file_asset(), use relative_staged_path() instead.

Returns:

  • (String)


86
87
88
# File 'asset_staging.rb', line 86

def absolute_staged_path()
  jsii_get_property("absoluteStagedPath")
end

#asset_hashString

A cryptographic hash of the asset.

Returns:

  • (String)


93
94
95
# File 'asset_staging.rb', line 93

def asset_hash()
  jsii_get_property("assetHash")
end

#is_archiveBoolean

Whether this asset is an archive (zip or jar).

Returns:

  • (Boolean)


100
101
102
# File 'asset_staging.rb', line 100

def is_archive()
  jsii_get_property("isArchive")
end

#nodeConstructs::Node

The tree node.

Returns:

  • (Constructs::Node)


57
58
59
# File 'asset_staging.rb', line 57

def node()
  jsii_get_property("node")
end

#packagingAWSCDK::FileAssetPackaging

How this asset should be packaged.



107
108
109
# File 'asset_staging.rb', line 107

def packaging()
  jsii_get_property("packaging")
end

#relative_staged_path(stack) ⇒ String

Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.

Only returns a relative path if the asset was staged, returns an absolute path if it was not staged.

A bundled asset might end up in the outDir and still not count as "staged"; if asset staging is disabled we're technically expected to reference source directories, but we don't have a source directory for the bundled outputs (as the bundle output is written to a temporary directory). Nevertheless, we will still return an absolute path.

A non-obvious directory layout may look like this:

  CLOUD ASSEMBLY ROOT
    +-- asset.12345abcdef/
    +-- assembly-Stage
          +-- MyStack.template.json
          +-- MyStack.assets.json <- will contain { "path": "../asset.12345abcdef" }

Parameters:

Returns:

  • (String)


164
165
166
167
# File 'asset_staging.rb', line 164

def relative_staged_path(stack)
  Jsii::Type.check_type(stack, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5TdGFjayJ9")), "stack")
  jsii_call_method("relativeStagedPath", [stack])
end

#source_pathString

The absolute path of the asset as it was referenced by the user.

Returns:

  • (String)


114
115
116
# File 'asset_staging.rb', line 114

def source_path()
  jsii_get_property("sourcePath")
end

#to_stringString

Returns a string representation of this construct.

Returns:

  • (String)


121
122
123
# File 'asset_staging.rb', line 121

def to_string()
  jsii_call_method("toString", [])
end

#with(*mixins) ⇒ Constructs::IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

Parameters:

  • mixins (Array<Constructs::IMixin>)

    The mixins to apply.

Returns:

  • (Constructs::IConstruct)

    This construct for chaining



134
135
136
137
138
139
# File 'asset_staging.rb', line 134

def with(*mixins)
  mixins.each_with_index do |item, index|
    Jsii::Type.check_type(item, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLklNaXhpbiJ9")), "mixins[#{index}]")
  end
  jsii_call_method("with", [*mixins])
end