Class RemovalPolicyProps
Properties for applying a removal policy.
Implements
Inherited Members
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class RemovalPolicyProps : IRemovalPolicyProps
Syntax (vb)
Public Class RemovalPolicyProps Implements IRemovalPolicyProps
Remarks
ExampleMetadata: infused
Examples
Construct scope;
Construct parent;
CfnBucket bucket;
// Apply DESTROY policy to all resources in a scope
RemovalPolicies.Of(scope).Destroy();
// Apply RETAIN policy to all resources in a scope
RemovalPolicies.Of(scope).Retain();
// Apply SNAPSHOT policy to all resources in a scope
RemovalPolicies.Of(scope).Snapshot();
// Apply RETAIN_ON_UPDATE_OR_DELETE policy to all resources in a scope
RemovalPolicies.Of(scope).RetainOnUpdateOrDelete();
// Apply RETAIN policy only to specific resource types
RemovalPolicies.Of(parent).Retain(new RemovalPolicyProps {
ApplyToResourceTypes = new [] { "AWS::DynamoDB::Table", bucket.CfnResourceType, CfnDBInstance.CFN_RESOURCE_TYPE_NAME }
});
// Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.Of(scope).Snapshot(new RemovalPolicyProps {
ExcludeResourceTypes = new [] { "AWS::Test::Resource" }
});
Synopsis
Constructors
| RemovalPolicyProps() | Properties for applying a removal policy. |
Properties
| ApplyToResourceTypes | Apply the removal policy only to specific resource types. |
| ExcludeResourceTypes | Exclude specific resource types from the removal policy. |
| Priority | The priority to use when applying this policy. |
Constructors
RemovalPolicyProps()
Properties for applying a removal policy.
public RemovalPolicyProps()
Remarks
ExampleMetadata: infused
Examples
Construct scope;
Construct parent;
CfnBucket bucket;
// Apply DESTROY policy to all resources in a scope
RemovalPolicies.Of(scope).Destroy();
// Apply RETAIN policy to all resources in a scope
RemovalPolicies.Of(scope).Retain();
// Apply SNAPSHOT policy to all resources in a scope
RemovalPolicies.Of(scope).Snapshot();
// Apply RETAIN_ON_UPDATE_OR_DELETE policy to all resources in a scope
RemovalPolicies.Of(scope).RetainOnUpdateOrDelete();
// Apply RETAIN policy only to specific resource types
RemovalPolicies.Of(parent).Retain(new RemovalPolicyProps {
ApplyToResourceTypes = new [] { "AWS::DynamoDB::Table", bucket.CfnResourceType, CfnDBInstance.CFN_RESOURCE_TYPE_NAME }
});
// Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.Of(scope).Snapshot(new RemovalPolicyProps {
ExcludeResourceTypes = new [] { "AWS::Test::Resource" }
});
Properties
ApplyToResourceTypes
Apply the removal policy only to specific resource types.
public string[]? ApplyToResourceTypes { get; set; }
Property Value
string[]
Remarks
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
Default: - apply to all resources
ExcludeResourceTypes
Exclude specific resource types from the removal policy.
public string[]? ExcludeResourceTypes { get; set; }
Property Value
string[]
Remarks
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
Default: - no exclusions
Priority
The priority to use when applying this policy.
public double? Priority { get; set; }
Property Value
Remarks
The priority affects only the order in which aspects are applied during synthesis. For RemovalPolicies, the last applied policy will override previous ones.
NOTE: Priority does NOT determine which policy "wins" when there are conflicts. The order of application determines the final policy, with later policies overriding earlier ones.
Default: - AspectPriority.MUTATING