CustomResourceProps

class aws_cdk.core.CustomResourceProps(*, service_token, pascal_case_properties=None, properties=None, removal_policy=None, resource_type=None)

Bases: object

Properties to provide a Lambda-backed custom resource.

Parameters:
  • service_token (str) – 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: const provider = new customresources.Provider(this, ‘ResourceProvider’, { onEventHandler, isCompleteHandler, // optional }); new CustomResource(this, ‘MyResource’, { serviceToken: provider.serviceToken, }); AWS Lambda function:: // invoke an AWS Lambda function when a lifecycle event occurs: new CustomResource(this, ‘MyResource’, { serviceToken: myFunction.functionArn, }); SNS topic:: // publish lifecycle events to an SNS topic: new CustomResource(this, ‘MyResource’, { serviceToken: myTopic.topicArn, });

  • pascal_case_properties (Optional[bool]) – Convert all property keys to pascal case. Default: false

  • properties (Optional[Mapping[str, Any]]) – Properties to pass to the Lambda. Default: - No properties.

  • removal_policy (Optional[RemovalPolicy]) – The policy to apply when this resource is removed from the application. Default: cdk.RemovalPolicy.Destroy

  • resource_type (Optional[str]) – 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). Default: - AWS::CloudFormation::CustomResource

ExampleMetadata:

infused

Example:

service_token = CustomResourceProvider.get_or_create(self, "Custom::MyCustomResourceType",
    code_directory=f"{__dirname}/my-handler",
    runtime=CustomResourceProviderRuntime.NODEJS_14_X,
    description="Lambda function created by the custom resource provider"
)

CustomResource(self, "MyResource",
    resource_type="Custom::MyCustomResourceType",
    service_token=service_token
)

Attributes

pascal_case_properties

Convert all property keys to pascal case.

Default:

false

properties

Properties to pass to the Lambda.

Default:
  • No properties.

removal_policy

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

Default:

cdk.RemovalPolicy.Destroy

resource_type

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

Default:
  • AWS::CloudFormation::CustomResource

See:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html#aws-cfn-resource-type-name

service_token

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 = customresources.Provider(self, "ResourceProvider",
    on_event_handler=on_event_handler,
    is_complete_handler=is_complete_handler
)

CustomResource(self, "MyResource",
    service_token=provider.service_token
)

AWS Lambda function:

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

SNS topic:

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