Enum RemovalPolicy

java.lang.Object
java.lang.Enum<RemovalPolicy>
software.amazon.awscdk.core.RemovalPolicy
All Implemented Interfaces:
Serializable, Comparable<RemovalPolicy>, java.lang.constant.Constable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:55.098Z") @Stability(Stable) public enum RemovalPolicy extends Enum<RemovalPolicy>
Possible values for a resource's Removal Policy.

The removal policy controls what happens to the resource if it stops being managed by CloudFormation. This can happen in one of three situations:

  • The resource is removed from the template, so CloudFormation stops managing it;
  • A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it;
  • The stack is deleted, so CloudFormation stops managing all resources in it.

The Removal Policy applies to all above cases.

Many stateful resources in the AWS Construct Library will accept a removalPolicy as a property, typically defaulting it to RETAIN.

If the AWS Construct Library resource does not accept a removalPolicy argument, you can always configure it by using the escape hatch mechanism, as shown in the following example:

 Bucket bucket;
 CfnResource cfnBucket = (CfnResource)bucket.node.findChild("Resource");
 cfnBucket.applyRemovalPolicy(RemovalPolicy.DESTROY);
 

Example:

 import software.amazon.awscdk.services.opensearchservice.*;
 GraphqlApi api;
 User user = new User(this, "User");
 Domain domain = Domain.Builder.create(this, "Domain")
         .version(EngineVersion.OPENSEARCH_1_2)
         .removalPolicy(RemovalPolicy.DESTROY)
         .fineGrainedAccessControl(AdvancedSecurityOptions.builder().masterUserArn(user.getUserArn()).build())
         .encryptionAtRest(EncryptionAtRestOptions.builder().enabled(true).build())
         .nodeToNodeEncryption(true)
         .enforceHttps(true)
         .build();
 OpenSearchDataSource ds = api.addOpenSearchDataSource("ds", domain);
 ds.createResolver(BaseResolverProps.builder()
         .typeName("Query")
         .fieldName("getTests")
         .requestMappingTemplate(MappingTemplate.fromString(JSON.stringify(Map.of(
                 "version", "2017-02-28",
                 "operation", "GET",
                 "path", "/id/post/_search",
                 "params", Map.of(
                         "headers", Map.of(),
                         "queryString", Map.of(),
                         "body", Map.of("from", 0, "size", 50))))))
         .responseMappingTemplate(MappingTemplate.fromString("[\n    #foreach($entry in $context.result.hits.hits)\n    #if( $velocityCount > 1 ) , #end\n    $utils.toJson($entry.get(\"_source\"))\n    #end\n  ]"))
         .build());
 
  • Enum Constant Details

  • Method Details

    • values

      public static RemovalPolicy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static RemovalPolicy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null