Class: AWSCDK::CustomResourceProps

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
custom_resource_props.rb

Overview

Properties to provide a Lambda-backed custom resource.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_token:, pascal_case_properties: nil, properties: nil, removal_policy: nil, resource_type: nil, service_timeout: nil) ⇒ CustomResourceProps

Returns a new instance of CustomResourceProps.

Parameters:

  • service_token (String)

    The ARN of the provider which implements this custom resource type.

  • pascal_case_properties (Boolean, nil) (defaults to: nil)

    Convert all property keys to pascal case.

  • properties (Hash{String => Object}, nil) (defaults to: nil)

    Properties to pass to the Lambda.

  • removal_policy (AWSCDK::RemovalPolicy, nil) (defaults to: nil)

    The policy to apply when this resource is removed from the application.

  • resource_type (String, nil) (defaults to: nil)

    For custom resources, you can specify AWS::CloudFormation::CustomResource (the default) as the resource type, or you can specify your own resource type name.

  • service_timeout (AWSCDK::Duration, nil) (defaults to: nil)

    The maximum time that can elapse before a custom resource operation times out.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'custom_resource_props.rb', line 13

def initialize(service_token:, pascal_case_properties: nil, properties: nil, removal_policy: nil, resource_type: nil, service_timeout: nil)
  @service_token = service_token
  Jsii::Type.check_type(@service_token, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "serviceToken")
  @pascal_case_properties = pascal_case_properties
  Jsii::Type.check_type(@pascal_case_properties, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "pascalCaseProperties") unless @pascal_case_properties.nil?
  @properties = properties
  Jsii::Type.check_type(@properties, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6ImFueSJ9LCJraW5kIjoibWFwIn19")), "properties") unless @properties.nil?
  @removal_policy = removal_policy
  Jsii::Type.check_type(@removal_policy, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5SZW1vdmFsUG9saWN5In0=")), "removalPolicy") unless @removal_policy.nil?
  @resource_type = resource_type
  Jsii::Type.check_type(@resource_type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "resourceType") unless @resource_type.nil?
  @service_timeout = service_timeout
  Jsii::Type.check_type(@service_timeout, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5EdXJhdGlvbiJ9")), "serviceTimeout") unless @service_timeout.nil?
end

Instance Attribute Details

#pascal_case_propertiesBoolean? (readonly)

Note:

Default: false

Convert all property keys to pascal case.

Returns:

  • (Boolean, nil)


77
78
79
# File 'custom_resource_props.rb', line 77

def pascal_case_properties
  @pascal_case_properties
end

#propertiesHash{String => Object}? (readonly)

Note:

Default: - No properties.

Properties to pass to the Lambda.

Values in this properties dictionary can possibly overwrite other values in CustomResourceProps E.g. ServiceToken and ServiceTimeout It is recommended to avoid using same keys that exist in CustomResourceProps

Returns:

  • (Hash{String => Object}, nil)


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

def properties
  @properties
end

#removal_policyAWSCDK::RemovalPolicy? (readonly)

Note:

Default: cdk.RemovalPolicy.Destroy

The policy to apply when this resource is removed from the application.

Returns:



91
92
93
# File 'custom_resource_props.rb', line 91

def removal_policy
  @removal_policy
end

#resource_typeString? (readonly)

Note:

Default: - AWS::CloudFormation::CustomResource

For custom resources, you can specify AWS::CloudFormation::CustomResource (the default) as the resource type, or you can specify your own resource type name.

For example, you can use "Custom::MyCustomResourceTypeName".

Custom resource type names must begin with "Custom::" and can include alphanumeric characters and the following characters: _@-. You can specify a custom resource type name up to a maximum length of 60 characters. You cannot change the type during an update.

Using your own resource type names helps you quickly differentiate the types of custom resources in your stack. For example, if you had two custom resources that conduct two different ping tests, you could name their type as Custom::PingTester to make them easily identifiable as ping testers (instead of using AWS::CloudFormation::CustomResource).



110
111
112
# File 'custom_resource_props.rb', line 110

def resource_type
  @resource_type
end

#service_timeoutAWSCDK::Duration? (readonly)

Note:

Default: Duration.seconds(3600)

The maximum time that can elapse before a custom resource operation times out.

The value must be between 1 second and 3600 seconds.

Maps to ServiceTimeout property for the AWS::CloudFormation::CustomResource resource

A token can be specified for this property, but it must be specified with Duration.seconds().

Examples:

stack = AWSCDK::Stack.new
dur_token = AWSCDK::CfnParameter.new(stack, "MyParameter", {
    type: "Number",
    default: 60,
})
AWSCDK::CustomResource.new(stack, "MyCustomResource", {
    service_token: "MyServiceToken",
    service_timeout: AWSCDK::Duration.seconds(dur_token.value_as_number),
})

Returns:



131
132
133
# File 'custom_resource_props.rb', line 131

def service_timeout
  @service_timeout
end

#service_tokenString (readonly)

The ARN of the provider which implements this custom resource type.

You can implement a provider by listening to raw AWS CloudFormation events and specify the ARN of an SNS topic (topic.topicArn) or the ARN of an AWS Lambda function (lambda.functionArn) or use the CDK's custom resource provider framework which makes it easier to implement robust providers.

Provider framework:

# use the provider framework from aws-cdk/custom-resources:
provider = AWSCDK::CustomResources::Provider.new(self, "ResourceProvider", {
    on_event_handler: on_event_handler,
    is_complete_handler: is_complete_handler,
})

AWSCDK::CustomResource.new(self, "MyResource", {
    service_token: provider.service_token,
})

AWS Lambda function (not recommended to use AWS Lambda Functions directly, see the module README):

# invoke an AWS Lambda function when a lifecycle event occurs:
AWSCDK::CustomResource.new(self, "MyResource", {
    service_token: my_function.function_arn,
})

SNS topic (not recommended to use AWS Lambda Functions directly, see the module README):

# publish lifecycle events to an SNS topic:
AWSCDK::CustomResource.new(self, "MyResource", {
    service_token: my_topic.topic_arn,
})

Maps to ServiceToken property for the AWS::CloudFormation::CustomResource resource

Returns:

  • (String)


72
73
74
# File 'custom_resource_props.rb', line 72

def service_token
  @service_token
end

Class Method Details

.jsii_propertiesObject



133
134
135
136
137
138
139
140
141
142
# File 'custom_resource_props.rb', line 133

def self.jsii_properties
  {
    :service_token => "serviceToken",
    :pascal_case_properties => "pascalCaseProperties",
    :properties => "properties",
    :removal_policy => "removalPolicy",
    :resource_type => "resourceType",
    :service_timeout => "serviceTimeout",
  }
end

Instance Method Details

#to_jsiiObject



144
145
146
147
148
149
150
151
152
153
154
155
# File 'custom_resource_props.rb', line 144

def to_jsii
  result = {}
  result.merge!({
    "serviceToken" => @service_token,
    "pascalCaseProperties" => @pascal_case_properties,
    "properties" => @properties,
    "removalPolicy" => @removal_policy,
    "resourceType" => @resource_type,
    "serviceTimeout" => @service_timeout,
  })
  result.compact
end