Table of Contents

Class CustomResourceProvider

Namespace
Amazon.CDK
Assembly
Amazon.CDK.dll

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

public class CustomResourceProvider : Construct, IConstruct, IConstruct, IDependable
Inheritance
CustomResourceProvider
Implements
IConstruct
Inherited Members

Examples

var provider = CustomResourceProvider.GetOrCreateProvider(this, "Custom::MyCustomResourceType", new CustomResourceProviderProps {
                 CodeDirectory = $"{__dirname}/my-handler",
                 Runtime = CustomResourceProviderRuntime.NODEJS_14_X
             });

             var roleArn = provider.RoleArn;

Remarks

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

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.

ExampleMetadata: infused

Constructors

CustomResourceProvider(Construct, string, ICustomResourceProviderProps)

public CustomResourceProvider(Construct scope, string id, ICustomResourceProviderProps props)

Parameters

scope Construct
id string
props ICustomResourceProviderProps

Properties

CodeHash

The hash of the lambda code backing this provider.

public virtual string CodeHash { get; }

Property Value

string

Remarks

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

RoleArn

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

public virtual string RoleArn { get; }

Property Value

string

ServiceToken

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

public virtual string ServiceToken { get; }

Property Value

string

Examples

CustomResourceProvider myProvider;


            new CustomResource(this, "MyCustomResource", new CustomResourceProps {
                ServiceToken = myProvider.ServiceToken,
                Properties = new Dictionary<string, object> {
                    { "myPropertyOne", "one" },
                    { "myPropertyTwo", "two" }
                }
            });

Methods

GetOrCreate(Construct, string, ICustomResourceProviderProps)

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

public static string GetOrCreate(Construct scope, string uniqueid, ICustomResourceProviderProps props)

Parameters

scope Construct

Construct scope.

uniqueid string

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

props ICustomResourceProviderProps

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.

GetOrCreateProvider(Construct, string, ICustomResourceProviderProps)

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

public static CustomResourceProvider GetOrCreateProvider(Construct scope, string uniqueid, ICustomResourceProviderProps props)

Parameters

scope Construct

Construct scope.

uniqueid string

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

props ICustomResourceProviderProps

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

Returns

CustomResourceProvider

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