Skip to content

Commit cd6e892

Browse files
committed
adds retain policy example
1 parent a251166 commit cd6e892

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.

src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources/index.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,32 @@ plan.addSelection("BackupPlanSelection", {
159159
});
160160
// highlight-end
161161
```
162+
163+
## Retaining resources on stack deletion
164+
165+
For example, if you would like to retain a resource on stack deletion, you can use the `applyRemovalPolicy` property on the resource to add a retention policy.
166+
167+
```ts title="amplify/backend.ts"
168+
import { defineBackend } from "@aws-amplify/backend";
169+
import { auth } from "./auth/resource";
170+
import { data } from "./data/resource";
171+
import { RemovalPolicy } from "aws-cdk-lib";
172+
import { storage } from "./storage/resource";
173+
174+
const backend = defineBackend({
175+
auth,
176+
data,
177+
storage,
178+
});
179+
180+
// highlight-start
181+
// Retain the S3 bucket on stack deletion
182+
backend.storage.resources.bucket.applyRemovalPolicy(RemovalPolicy.RETAIN);
183+
184+
// Retain the Cognito user pool on stack deletion
185+
backend.auth.resources.userPool.applyRemovalPolicy(RemovalPolicy.RETAIN);
186+
187+
// Retain the DynamoDB table on stack deletion
188+
backend.data.resources.cfnResources.amplifyDynamoDbTables["Todo"].applyRemovalPolicy(RemovalPolicy.RETAIN);
189+
// highlight-end
190+
```

0 commit comments

Comments
 (0)