Class: AWSCDK::S3Assets::Asset

Inherits:
Constructs::Construct
  • Object
show all
Includes:
IAsset
Defined in:
s3_assets/asset.rb

Overview

An asset represents a local file or directory, which is automatically uploaded to S3 and then can be referenced within a CDK application.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, id, props) ⇒ Asset

Returns a new instance of Asset.

Parameters:



12
13
14
15
16
17
18
# File 's3_assets/asset.rb', line 12

def initialize(scope, id, props)
  props = props.is_a?(Hash) ? ::AWSCDK::S3Assets::AssetProps.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("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfYXNzZXRzLkFzc2V0UHJvcHMifQ==")), "props")
  Jsii::Object.instance_method(:initialize).bind(self).call(scope, id, props)
end

Class Method Details

.jsii_overridable_methodsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 's3_assets/asset.rb', line 20

def self.jsii_overridable_methods
  {
    :node => { kind: :property, name: "node", is_optional: false },
    :asset_hash => { kind: :property, name: "assetHash", is_optional: false },
    :asset_path => { kind: :property, name: "assetPath", is_optional: false },
    :bucket => { kind: :property, name: "bucket", is_optional: false },
    :http_url => { kind: :property, name: "httpUrl", is_optional: false },
    :is_file => { kind: :property, name: "isFile", is_optional: false },
    :is_zip_archive => { kind: :property, name: "isZipArchive", is_optional: false },
    :s3_bucket_name => { kind: :property, name: "s3BucketName", is_optional: false },
    :s3_object_key => { kind: :property, name: "s3ObjectKey", is_optional: false },
    :s3_object_url => { kind: :property, name: "s3ObjectUrl", is_optional: false },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :with => { kind: :method, name: "with", is_optional: false },
    :add_resource_metadata => { kind: :method, name: "addResourceMetadata", is_optional: false },
    :grant_read => { kind: :method, name: "grantRead", is_optional: false },
  }
end

Instance Method Details

#add_resource_metadata(resource, resource_property) ⇒ void

This method returns an undefined value.

Adds CloudFormation template metadata to the specified resource with information that indicates which resource property is mapped to this local asset.

This can be used by tools such as SAM CLI to provide local experience such as local invocation and debugging of Lambda functions.

Asset metadata will only be included if the stack is synthesized with the "aws:cdk:enable-asset-metadata" context key defined, which is the default behavior when synthesizing via the CDK Toolkit.

Parameters:

  • resource (AWSCDK::CfnResource)

    The CloudFormation resource which is using this asset [disable-awslint:ref-via-interface].

  • resource_property (String)

    The property name where this asset is referenced (e.g. "Code" for AWS::Lambda::Function).

See Also:



162
163
164
165
166
# File 's3_assets/asset.rb', line 162

def (resource, resource_property)
  Jsii::Type.check_type(resource, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5DZm5SZXNvdXJjZSJ9")), "resource")
  Jsii::Type.check_type(resource_property, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "resourceProperty")
  jsii_call_method("addResourceMetadata", [resource, resource_property])
end

#asset_hashString

A hash of this asset, which is available at construction time.

As this is a plain string, it can be used in construct IDs in order to enforce creation of a new resource when the content hash has changed.

Returns:

  • (String)


53
54
55
# File 's3_assets/asset.rb', line 53

def asset_hash()
  jsii_get_property("assetHash")
end

#asset_pathString

The path to the asset, relative to the current Cloud Assembly.

If asset staging is disabled, this will just be the original path. If asset staging is enabled it will be the staged path.

Returns:

  • (String)


63
64
65
# File 's3_assets/asset.rb', line 63

def asset_path()
  jsii_get_property("assetPath")
end

#bucketAWSCDK::S3::IBucket

The S3 bucket in which this asset resides.

Returns:



70
71
72
# File 's3_assets/asset.rb', line 70

def bucket()
  jsii_get_property("bucket")
end

#grant_read(grantee) ⇒ void

This method returns an undefined value.

Grants read permissions to the principal on the assets bucket.

[disable-awslint:no-grants]

Parameters:



174
175
176
177
# File 's3_assets/asset.rb', line 174

def grant_read(grantee)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  jsii_call_method("grantRead", [grantee])
end

#http_urlString

Attribute which represents the S3 HTTP URL of this asset.

For example, https://s3.us-west-1.amazonaws.com/bucket/key

Returns:

  • (String)


79
80
81
# File 's3_assets/asset.rb', line 79

def http_url()
  jsii_get_property("httpUrl")
end

#is_fileBoolean

Indicates if this asset is a single file.

Allows constructs to ensure that the correct file type was used.

Returns:

  • (Boolean)


89
90
91
# File 's3_assets/asset.rb', line 89

def is_file()
  jsii_get_property("isFile")
end

#is_zip_archiveBoolean

Indicates if this asset is a zip archive.

Allows constructs to ensure that the correct file type was used.

Returns:

  • (Boolean)


99
100
101
# File 's3_assets/asset.rb', line 99

def is_zip_archive()
  jsii_get_property("isZipArchive")
end

#nodeConstructs::Node

The tree node.

Returns:

  • (Constructs::Node)


42
43
44
# File 's3_assets/asset.rb', line 42

def node()
  jsii_get_property("node")
end

#s3_bucket_nameString

Attribute that represents the name of the bucket this asset exists in.

Returns:

  • (String)


106
107
108
# File 's3_assets/asset.rb', line 106

def s3_bucket_name()
  jsii_get_property("s3BucketName")
end

#s3_object_keyString

Attribute which represents the S3 object key of this asset.

Returns:

  • (String)


113
114
115
# File 's3_assets/asset.rb', line 113

def s3_object_key()
  jsii_get_property("s3ObjectKey")
end

#s3_object_urlString

Attribute which represents the S3 URL of this asset.

For example, s3://bucket/key

Returns:

  • (String)


122
123
124
# File 's3_assets/asset.rb', line 122

def s3_object_url()
  jsii_get_property("s3ObjectUrl")
end

#to_stringString

Returns a string representation of this construct.

Returns:

  • (String)


129
130
131
# File 's3_assets/asset.rb', line 129

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



142
143
144
145
146
147
# File 's3_assets/asset.rb', line 142

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