Class CustomResourceProvider
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
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 theiam
library already depends on the CDKcore
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.
Example:
CustomResourceProvider provider = CustomResourceProvider.getOrCreateProvider(this, "Custom::MyCustomResourceType", CustomResourceProviderProps.builder() .codeDirectory(String.format("%s/my-handler", __dirname)) .runtime(CustomResourceProviderRuntime.NODEJS_18_X) .build()); provider.addToRolePolicy(Map.of( "Effect", "Allow", "Action", "s3:GetObject", "Resource", "*"));
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default, software.constructs.IConstruct.Jsii$Proxy
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CustomResourceProvider
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
CustomResourceProvider
(software.amazon.jsii.JsiiObjectRef objRef) protected
CustomResourceProvider
(software.constructs.Construct scope, String id, CustomResourceProviderProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToRolePolicy
(Object statement) Add an IAM policy statement to the inline policy of the provider's lambda function's role.The hash of the lambda code backing this provider.static String
getOrCreate
(software.constructs.Construct scope, String uniqueid, CustomResourceProviderProps props) Returns a stack-level singleton ARN (service token) for the custom resource provider.static CustomResourceProvider
getOrCreateProvider
(software.constructs.Construct scope, String uniqueid, CustomResourceProviderProps props) Returns a stack-level singleton for the custom resource provider.The ARN of the provider's AWS Lambda function role.The ARN of the provider's AWS Lambda function which should be used as theserviceToken
when defining a custom resource.Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
CustomResourceProvider
protected CustomResourceProvider(software.amazon.jsii.JsiiObjectRef objRef) -
CustomResourceProvider
protected CustomResourceProvider(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
CustomResourceProvider
@Stability(Stable) protected CustomResourceProvider(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CustomResourceProviderProps props) - Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
getOrCreate
@Stability(Stable) @NotNull public static String getOrCreate(@NotNull software.constructs.Construct scope, @NotNull String uniqueid, @NotNull CustomResourceProviderProps props) Returns a stack-level singleton ARN (service token) for the custom resource provider.- Parameters:
scope
- Construct scope. This parameter is required.uniqueid
- A globally unique id that will be used for the stack-level construct. This parameter is required.props
- Provider properties which will only be applied when the provider is first created. This parameter is required.- Returns:
- the service token of the custom resource provider, which should be
used when defining a
CustomResource
.
-
getOrCreateProvider
@Stability(Stable) @NotNull public static CustomResourceProvider getOrCreateProvider(@NotNull software.constructs.Construct scope, @NotNull String uniqueid, @NotNull CustomResourceProviderProps props) Returns a stack-level singleton for the custom resource provider.- Parameters:
scope
- Construct scope. This parameter is required.uniqueid
- A globally unique id that will be used for the stack-level construct. This parameter is required.props
- Provider properties which will only be applied when the provider is first created. This parameter is required.- Returns:
- the service token of the custom resource provider, which should be
used when defining a
CustomResource
.
-
addToRolePolicy
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.Example:
CustomResourceProvider myProvider; myProvider.addToRolePolicy(Map.of( "Effect", "Allow", "Action", "s3:GetObject", "Resource", "*"));
- Parameters:
statement
- This parameter is required.
-
getCodeHash
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.
-
getRoleArn
The ARN of the provider's AWS Lambda function role. -
getServiceToken
The ARN of the provider's AWS Lambda function which should be used as theserviceToken
when defining a custom resource.Example:
CustomResourceProvider myProvider; CustomResource.Builder.create(this, "MyCustomResource") .serviceToken(myProvider.getServiceToken()) .properties(Map.of( "myPropertyOne", "one", "myPropertyTwo", "two")) .build();
-