RemovalPolicyProps Struct
Properties for applying a removal policy.
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'],
});
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.