@Generated(value="jsii-pacmak/1.73.0 (build 6faeda3)", date="2023-01-31T18:36:45.199Z") public enum RemovalPolicy extends java.lang.Enum<RemovalPolicy>
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 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 and Description |
---|
DESTROY
This is the default removal policy.
|
RETAIN
This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
|
SNAPSHOT
This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later.
|
Modifier and Type | Method and Description |
---|---|
static RemovalPolicy |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static RemovalPolicy[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final RemovalPolicy DESTROY
It means that when the resource is removed from the app, it will be physically destroyed.
public static final RemovalPolicy RETAIN
public static final RemovalPolicy SNAPSHOT
Only available for some stateful resources, like databases, EFS volumes, etc.
public static RemovalPolicy[] values()
for (RemovalPolicy c : RemovalPolicy.values()) System.out.println(c);
public static RemovalPolicy valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null