RemovalPolicyProps Struct
Properties for applying a removal policy.
| Source | core/lib/removal-policies.ts |
|---|---|
| Type last changed |
Example
ts
declare const scope: Construct;
declare const parent: Construct;
declare const bucket: s3.CfnBucket;
// 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({
applyToResourceTypes: [
'AWS::DynamoDB::Table',
bucket.cfnResourceType, // 'AWS::S3::Bucket'
rds.CfnDBInstance.CFN_RESOURCE_TYPE_NAME, // 'AWS::RDS::DBInstance'
],
});
// Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.of(scope).snapshot({
excludeResourceTypes: ['AWS::Test::Resource'],
});
python
# scope: Construct
# parent: Construct
# bucket: s3.CfnBucket
# 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).retain_on_update_or_delete()
# Apply RETAIN policy only to specific resource types
RemovalPolicies.of(parent).retain(
apply_to_resource_types=["AWS::DynamoDB::Table", bucket.cfn_resource_type, rds.CfnDBInstance.CFN_RESOURCE_TYPE_NAME
]
)
# Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.of(scope).snapshot(
exclude_resource_types=["AWS::Test::Resource"]
)
java
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(RemovalPolicyProps.builder()
.applyToResourceTypes(List.of("AWS::DynamoDB::Table", bucket.getCfnResourceType(), CfnDBInstance.CFN_RESOURCE_TYPE_NAME))
.build());
// Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.of(scope).snapshot(RemovalPolicyProps.builder()
.excludeResourceTypes(List.of("AWS::Test::Resource"))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
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" }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var scope Construct
var parent Construct
var bucket CfnBucket
// Apply DESTROY policy to all resources in a scope
awscdk.RemovalPolicies_Of(*scope).Destroy()
// Apply RETAIN policy to all resources in a scope
awscdk.RemovalPolicies_Of(*scope).Retain()
// Apply SNAPSHOT policy to all resources in a scope
awscdk.RemovalPolicies_Of(*scope).Snapshot()
// Apply RETAIN_ON_UPDATE_OR_DELETE policy to all resources in a scope
awscdk.RemovalPolicies_Of(*scope).RetainOnUpdateOrDelete()
// Apply RETAIN policy only to specific resource types
awscdk.RemovalPolicies_Of(parent).Retain(&RemovalPolicyProps{
ApplyToResourceTypes: []*string{
jsii.String("AWS::DynamoDB::Table"),
bucket.CfnResourceType,
rds.CfnDBInstance_CFN_RESOURCE_TYPE_NAME(),
},
})
// Apply SNAPSHOT policy excluding specific resource types
awscdk.RemovalPolicies_Of(*scope).Snapshot(&RemovalPolicyProps{
ExcludeResourceTypes: []*string{
jsii.String("AWS::Test::Resource"),
},
})
Properties
applyToResourceTypesoptionalstring[]apply_to_resource_typesoptionaltyping.List[str]applyToResourceTypesoptionalList<String>ApplyToResourceTypesoptionalstring[]ApplyToResourceTypesoptional*[]*string #Apply the removal policy only to specific resource types.
Default: apply to all resources
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
excludeResourceTypesoptionalstring[]exclude_resource_typesoptionaltyping.List[str]excludeResourceTypesoptionalList<String>ExcludeResourceTypesoptionalstring[]ExcludeResourceTypesoptional*[]*string #Exclude specific resource types from the removal policy.
Default: no exclusions
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
priorityoptionalnumberpriorityoptionalint | floatpriorityoptionalNumberPriorityoptionaldoublePriorityoptional*float64 = AspectPriority.MUTATING #The priority to use when applying this policy.
notes
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.