interface RemovalPolicyProps
Language | Type name |
---|---|
![]() | Amazon.CDK.RemovalPolicyProps |
![]() | github.com/aws/aws-cdk-go/awscdk/v2#RemovalPolicyProps |
![]() | software.amazon.awscdk.RemovalPolicyProps |
![]() | aws_cdk.RemovalPolicyProps |
![]() | aws-cdk-lib » RemovalPolicyProps |
Properties for applying a removal policy.
Example
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
Name | Type | Description |
---|---|---|
apply | string[] | Apply the removal policy only to specific resource types. |
exclude | string[] | Exclude specific resource types from the removal policy. |
priority? | number | The priority to use when applying this policy. |
applyToResourceTypes?
Type:
string[]
(optional, default: apply to all resources)
Apply the removal policy only to specific resource types.
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
excludeResourceTypes?
Type:
string[]
(optional, default: no exclusions)
Exclude specific resource types from the removal policy.
Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').
priority?
Type:
number
(optional, default: AspectPriority.MUTATING)
The priority to use when applying this policy.
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.