Skip to content

Commit 66148d1

Browse files
authored
adds retain policy example (#8051)
* adds retain policy example * rm next-env change
1 parent c3d29d0 commit 66148d1

File tree

1 file changed

+29
-0
lines changed
  • src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources

1 file changed

+29
-0
lines changed

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)