Skip to content

Commit aa7c160

Browse files
authored
docs(core): update CustomResource documentation (#18156)
Make the use and implications of CustomResources in the `core` library a bit more clear. Strongly direct users to the `custom-resources` module. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8c5894a commit aa7c160

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

packages/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,26 @@ export enum CustomResourceProviderRuntime {
111111
}
112112

113113
/**
114-
* An AWS-Lambda backed custom resource provider.
114+
* An AWS-Lambda backed custom resource provider, for CDK Construct Library constructs
115115
*
116+
* This is a provider for `CustomResource` constructs, backed by an AWS Lambda
117+
* Function. It only supports NodeJS runtimes.
118+
*
119+
* **This is not a generic custom resource provider class**. It is specifically
120+
* intended to be used only by constructs in the AWS CDK Construct Library, and
121+
* only exists here because of reverse dependency issues (for example, it cannot
122+
* use `iam.PolicyStatement` objects, since the `iam` library already depends on
123+
* the CDK `core` library and we cannot have cyclic dependencies).
124+
*
125+
* If you are not writing constructs for the AWS Construct Library, you should
126+
* use the `Provider` class in the `custom-resources` module instead, which has
127+
* a better API and supports all Lambda runtimes, not just Node.
128+
*
129+
* N.B.: When you are writing Custom Resource Providers, there are a number of
130+
* lifecycle events you have to pay attention to. These are documented in the
131+
* README of the `custom-resources` module. Be sure to give the documentation
132+
* in that module a read, regardless of whether you end up using the Provider
133+
* class in there or this one.
116134
*/
117135
export class CustomResourceProvider extends CoreConstruct {
118136
/**

packages/@aws-cdk/core/lib/custom-resource.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,25 @@ export interface CustomResourceProps {
9898
}
9999

100100
/**
101-
* Custom resource that is implemented using a Lambda
101+
* Instantiation of a custom resource, whose implementation is provided a Provider
102102
*
103-
* As a custom resource author, you should be publishing a subclass of this class
104-
* that hides the choice of provider, and accepts a strongly-typed properties
105-
* object with the properties your provider accepts.
103+
* This class is intended to be used by construct library authors. Application
104+
* builder should not be able to tell whether or not a construct is backed by
105+
* a custom resource, and so the use of this class should be invisible.
106+
*
107+
* Instead, construct library authors declare a custom construct that hides the
108+
* choice of provider, and accepts a strongly-typed properties object with the
109+
* properties your provider accepts.
110+
*
111+
* Your custom resource provider (identified by the `serviceToken` property)
112+
* can be one of 4 constructs:
113+
*
114+
* - If you are authoring a construct library or application, we recommend you
115+
* use the `Provider` class in the `custom-resources` module.
116+
* - If you are authoring a construct for the CDK's AWS Construct Library,
117+
* you should use the `CustomResourceProvider` construct in this package.
118+
* - If you want full control over the provider, you can always directly use
119+
* a Lambda Function or SNS Topic by passing the ARN into `serviceToken`.
106120
*
107121
* @resource AWS::CloudFormation::CustomResource
108122
*/

0 commit comments

Comments
 (0)