Skip to content

Commit

Permalink
readme updated
Browse files Browse the repository at this point in the history
  • Loading branch information
watany-dev committed Dec 26, 2024
1 parent dec21e2 commit da6b4c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
42 changes: 10 additions & 32 deletions packages/aws-cdk-lib/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1798,12 +1798,22 @@ The `RemovalPolicies` class provides a convenient way to manage removal policies

### Usage

Creates a new instance of RemovalPolicies for the given scope.

```typescript
import { RemovalPolicies } from 'aws-cdk-lib';
// Apply DESTROY policy to all resources in a scope
RemovalPolicies.of(scope).destroy();
// Apply DESTROY policy (overwrited)
RemovalPolicies.of(scope).snapshot();
RemovalPolicies.of(scope).destroy({ overwrite: true }));
// Apply DESTROY policy (priority)
RemovalPolicies.of(stack).retainOnUpdateOrDelete({ priority: 250 });
RemovalPolicies.of(stack).destroy({ priority: 10 });
// Apply RETAIN policy only to specific resource types
RemovalPolicies.of(parent).retain({
applyToResourceTypes: [
Expand All @@ -1813,44 +1823,12 @@ RemovalPolicies.of(parent).retain({
],
});
// Apply SNAPSHOT policy excluding specific resource types
RemovalPolicies.of(scope).snapshot({
excludeResourceTypes: ['AWS::Test::Resource'],
});
// Apply RETAIN_ON_UPDATE_OR_DELETE policy
RemovalPolicies.of(scope).retainOnUpdateOrDelete();
```

### RemovalPolicies.of(scope)

Creates a new instance of RemovalPolicies for the given scope.

#### Methods

- `apply(policy: RemovalPolicy, props?: RemovalPolicyProps)`: Apply a custom removal policy
- `destroy(props?: RemovalPolicyProps)`: Apply DESTROY removal policy
- `retain(props?: RemovalPolicyProps)`: Apply RETAIN removal policy
- `snapshot(props?: RemovalPolicyProps)`: Apply SNAPSHOT removal policy
- `retainOnUpdateOrDelete(props?: RemovalPolicyProps)`: Apply RETAIN_ON_UPDATE_OR_DELETE removal policy

#### `RemovalPolicyProps` Interface

Additional configuration options for applying removal policies.

- **`applyToResourceTypes?`**: _(optional)_
Array of CloudFormation resource types (e.g., `'AWS::S3::Bucket'`) to which the removal policy should be applied.
Defaults to applying to all resources.

- **`excludeResourceTypes?`**: _(optional)_
Array of CloudFormation resource types to exclude from applying the removal policy.
Defaults to no exclusions.

- **`overwrite?`**: _(optional)_
If `true`, the removal policy will overwrite any existing policy already set on the resource. Defaults to `false`.

#### Behavior Summary

- When `overwrite` is `false` (default):
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/core/lib/removal-policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export interface RemovalPolicyProps {
readonly priority?: number;
}

/**
* The RemovalPolicyAspect handles applying a removal policy to resources
*/
class RemovalPolicyAspect implements IAspect {
constructor(
private readonly policy: RemovalPolicy,
Expand Down

0 comments on commit da6b4c5

Please sign in to comment.