Class CustomResource

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IConstruct, IDependable, IResource, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct
Direct Known Subclasses:
CustomResource

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:54.999Z") @Stability(Stable) public class CustomResource extends Resource
Instantiation of a custom resource, whose implementation is provided a Provider.

This class is intended to be used by construct library authors. Application builder should not be able to tell whether or not a construct is backed by a custom resource, and so the use of this class should be invisible.

Instead, construct library authors declare a custom construct that hides the choice of provider, and accepts a strongly-typed properties object with the properties your provider accepts.

Your custom resource provider (identified by the serviceToken property) can be one of 4 constructs:

  • If you are authoring a construct library or application, we recommend you use the Provider class in the custom-resources module.
  • If you are authoring a construct for the CDK's AWS Construct Library, you should use the CustomResourceProvider construct in this package.
  • If you want full control over the provider, you can always directly use a Lambda Function or SNS Topic by passing the ARN into serviceToken.

Example:

 String serviceToken = CustomResourceProvider.getOrCreate(this, "Custom::MyCustomResourceType", CustomResourceProviderProps.builder()
         .codeDirectory(String.format("%s/my-handler", __dirname))
         .runtime(CustomResourceProviderRuntime.NODEJS_14_X)
         .description("Lambda function created by the custom resource provider")
         .build());
 CustomResource.Builder.create(this, "MyResource")
         .resourceType("Custom::MyCustomResourceType")
         .serviceToken(serviceToken)
         .build();
 
  • Constructor Details

    • CustomResource

      protected CustomResource(software.amazon.jsii.JsiiObjectRef objRef)
    • CustomResource

      protected CustomResource(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CustomResource

      @Stability(Stable) public CustomResource(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CustomResourceProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • getAtt

      @Stability(Stable) @NotNull public Reference getAtt(@NotNull String attributeName)
      Returns the value of an attribute of the custom resource of an arbitrary type.

      Attributes are returned from the custom resource provider through the Data map where the key is the attribute name.

      Parameters:
      attributeName - the name of the attribute. This parameter is required.
      Returns:
      a token for Fn::GetAtt. Use Token.asXxx to encode the returned Reference as a specific type or use the convenience getAttString for string attributes.
    • getAttString

      @Stability(Stable) @NotNull public String getAttString(@NotNull String attributeName)
      Returns the value of an attribute of the custom resource of type string.

      Attributes are returned from the custom resource provider through the Data map where the key is the attribute name.

      Parameters:
      attributeName - the name of the attribute. This parameter is required.
      Returns:
      a token for Fn::GetAtt encoded as a string.
    • getRef

      @Stability(Stable) @NotNull public String getRef()
      The physical name of this custom resource.