Class: AWSCDK::CustomResourceProvider

Inherits:
CustomResourceProviderBase
  • Object
show all
Defined in:
custom_resource_provider.rb

Overview

An AWS-Lambda backed custom resource provider, for CDK Construct Library constructs.

This is a provider for CustomResource constructs, backed by an AWS Lambda Function. It only supports NodeJS runtimes.

Application builders do not need to use this provider type. This is not a generic custom resource provider class. It is specifically intended to be used only by constructs in the AWS CDK Construct Library, and only exists here because of reverse dependency issues (for example, it cannot use iam.PolicyStatement objects, since the iam library already depends on the CDK core library and we cannot have cyclic dependencies).

If you are not writing constructs for the AWS Construct Library, you should use the Provider class in the custom-resources module instead, which has a better API and supports all Lambda runtimes, not just Node.

N.B.: When you are writing Custom Resource Providers, there are a number of lifecycle events you have to pay attention to. These are documented in the README of the custom-resources module. Be sure to give the documentation in that module a read, regardless of whether you end up using the Provider class in there or this one.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, id, props) ⇒ CustomResourceProvider

Returns a new instance of CustomResourceProvider.

Parameters:



31
32
33
34
35
36
37
# File 'custom_resource_provider.rb', line 31

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

Class Method Details

.get_or_create(scope, uniqueid, props) ⇒ String

Returns a stack-level singleton ARN (service token) for the custom resource provider.

Parameters:

  • scope (Constructs::Construct)

    Construct scope.

  • uniqueid (String)

    A globally unique id that will be used for the stack-level construct.

  • props (AWSCDK::CustomResourceProviderProps)

    Provider properties which will only be applied when the provider is first created.

Returns:

  • (String)

    the service token of the custom resource provider, which should be used when defining a CustomResource.



57
58
59
60
61
62
63
# File 'custom_resource_provider.rb', line 57

def self.get_or_create(scope, uniqueid, props)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(uniqueid, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "uniqueid")
  props = props.is_a?(Hash) ? ::AWSCDK::CustomResourceProviderProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5DdXN0b21SZXNvdXJjZVByb3ZpZGVyUHJvcHMifQ==")), "props")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.CustomResourceProvider", "getOrCreate", [scope, uniqueid, props])
end

.get_or_create_provider(scope, uniqueid, props) ⇒ AWSCDK::CustomResourceProvider

Returns a stack-level singleton for the custom resource provider.

Parameters:

  • scope (Constructs::Construct)

    Construct scope.

  • uniqueid (String)

    A globally unique id that will be used for the stack-level construct.

  • props (AWSCDK::CustomResourceProviderProps)

    Provider properties which will only be applied when the provider is first created.

Returns:

  • (AWSCDK::CustomResourceProvider)

    the service token of the custom resource provider, which should be used when defining a CustomResource.



71
72
73
74
75
76
77
# File 'custom_resource_provider.rb', line 71

def self.get_or_create_provider(scope, uniqueid, props)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(uniqueid, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "uniqueid")
  props = props.is_a?(Hash) ? ::AWSCDK::CustomResourceProviderProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5DdXN0b21SZXNvdXJjZVByb3ZpZGVyUHJvcHMifQ==")), "props")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.CustomResourceProvider", "getOrCreateProvider", [scope, uniqueid, props])
end

.jsii_overridable_methodsObject



39
40
41
42
43
44
45
46
47
48
49
# File 'custom_resource_provider.rb', line 39

def self.jsii_overridable_methods
  {
    :node => { kind: :property, name: "node", is_optional: false },
    :code_hash => { kind: :property, name: "codeHash", is_optional: false },
    :role_arn => { kind: :property, name: "roleArn", is_optional: false },
    :service_token => { kind: :property, name: "serviceToken", is_optional: false },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :with => { kind: :method, name: "with", is_optional: false },
    :add_to_role_policy => { kind: :method, name: "addToRolePolicy", is_optional: false },
  }
end

Instance Method Details

#add_to_role_policy(statement) ⇒ void

This method returns an undefined value.

Add an IAM policy statement to the inline policy of the provider's lambda function's role.

Please note: this is a direct IAM JSON policy blob, not a iam.PolicyStatement object like you will see in the rest of the CDK.

Examples:

# Example automatically generated from non-compiling source. May contain errors.
my_provider = nil

my_provider.add_to_role_policy({
    Effect: "Allow",
    Action: "s3:GetObject",
    Resource: "*",
})

Parameters:

  • statement (Object)


149
150
151
152
# File 'custom_resource_provider.rb', line 149

def add_to_role_policy(statement)
  Jsii::Type.check_type(statement, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "statement")
  jsii_call_method("addToRolePolicy", [statement])
end

#code_hashString

The hash of the lambda code backing this provider.

Can be used to trigger updates on code changes, even when the properties of a custom resource remain unchanged.

Returns:

  • (String)


92
93
94
# File 'custom_resource_provider.rb', line 92

def code_hash()
  jsii_get_property("codeHash")
end

#nodeConstructs::Node

The tree node.

Returns:

  • (Constructs::Node)


82
83
84
# File 'custom_resource_provider.rb', line 82

def node()
  jsii_get_property("node")
end

#role_arnString

The ARN of the provider's AWS Lambda function role.

Returns:

  • (String)


99
100
101
# File 'custom_resource_provider.rb', line 99

def role_arn()
  jsii_get_property("roleArn")
end

#service_tokenString

The ARN of the provider's AWS Lambda function which should be used as the serviceToken when defining a custom resource.

Returns:

  • (String)


106
107
108
# File 'custom_resource_provider.rb', line 106

def service_token()
  jsii_get_property("serviceToken")
end

#to_stringString

Returns a string representation of this construct.

Returns:

  • (String)


113
114
115
# File 'custom_resource_provider.rb', line 113

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



126
127
128
129
130
131
# File 'custom_resource_provider.rb', line 126

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