# RemovalPolicyProps

Properties for applying a removal policy.

- Source: [`core/lib/removal-policies.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/removal-policies.ts#L12)
- Type last changed: v2.183.0 · 12 Mar 2025

## 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

- `applyToResourceTypes`: 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').

- `excludeResourceTypes`: string[] — Exclude specific resource types from the removal policy.

  **Default:** no exclusions

  Can be a CloudFormation resource type string (e.g., 'AWS::S3::Bucket').

- `priority`: number = 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.
