Class RemovalPolicy
Possible values for a resource's Removal Policy.
Inheritance
Namespace: Amazon.CDK
Assembly: Amazon.CDK.dll
Syntax (csharp)
public sealed class RemovalPolicy : Enum
Syntax (vb)
Public NotInheritable Class RemovalPolicy
Inherits
Enum
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
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
]")
});
Synopsis
Fields
| 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. |
| value__ |
Fields
DESTROY
This is the default removal policy.
public const RemovalPolicy DESTROY
Field Value
| Type | Description |
|---|---|
| RemovalPolicy |
Remarks
It means that when the resource is removed from the app, it will be physically destroyed.
RETAIN
This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
public const RemovalPolicy RETAIN
Field Value
| Type | Description |
|---|---|
| RemovalPolicy |
SNAPSHOT
This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later.
public const RemovalPolicy SNAPSHOT
Field Value
| Type | Description |
|---|---|
| RemovalPolicy |
Remarks
Only available for some stateful resources, like databases, EFS volumes, etc.
value__
public int value__
Field Value
| Type | Description |
|---|---|
| System.Int32 |