Enum RemovalPolicy
Possible values for a resource's Removal Policy.
public enum RemovalPolicy
Fields
DESTROY = 0
This is the default removal policy.
RETAIN = 1
This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
SNAPSHOT = 2
This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later.
Examples
using Amazon.CDK.AWS.OpenSearchService;
GraphqlApi api;
var user = new User(this, "User");
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_2,
RemovalPolicy = RemovalPolicy.DESTROY,
FineGrainedAccessControl = new AdvancedSecurityOptions { MasterUserArn = user.UserArn },
EncryptionAtRest = new EncryptionAtRestOptions { Enabled = true },
NodeToNodeEncryption = true,
EnforceHttps = true
});
var ds = api.AddOpenSearchDataSource("ds", domain);
ds.CreateResolver(new BaseResolverProps {
TypeName = "Query",
FieldName = "getTests",
RequestMappingTemplate = MappingTemplate.FromString(JSON.Stringify(new Dictionary<string, object> {
{ "version", "2017-02-28" },
{ "operation", "GET" },
{ "path", "/id/post/_search" },
{ "params", new Struct {
Headers = new Struct { },
QueryString = new Struct { },
Body = new Struct { From = 0, Size = 50 }
} }
})),
ResponseMappingTemplate = MappingTemplate.FromString(@"[
#foreach($entry in $context.result.hits.hits)
#if( $velocityCount > 1 ) , #end
$utils.toJson($entry.get(""_source""))
#end
]")
});
Remarks
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;
var cfnBucket = (CfnResource)bucket.Node.FindChild("Resource");
cfnBucket.ApplyRemovalPolicy(RemovalPolicy.DESTROY);
ExampleMetadata: infused