From cd6e892c1bba4f4725b9f36d41da096a88f5b897 Mon Sep 17 00:00:00 2001 From: ykethan Date: Thu, 24 Oct 2024 15:34:39 -0400 Subject: [PATCH 1/2] adds retain policy example --- next-env.d.ts | 2 +- .../deletion-backup-resources/index.mdx | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03dc6c..a4a7b3f5cfa 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources/index.mdx index 1dbb7623b43..d1c468ed93e 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/deletion-backup-resources/index.mdx @@ -159,3 +159,32 @@ plan.addSelection("BackupPlanSelection", { }); // highlight-end ``` + +## Retaining resources on stack deletion + +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. + +```ts title="amplify/backend.ts" +import { defineBackend } from "@aws-amplify/backend"; +import { auth } from "./auth/resource"; +import { data } from "./data/resource"; +import { RemovalPolicy } from "aws-cdk-lib"; +import { storage } from "./storage/resource"; + +const backend = defineBackend({ + auth, + data, + storage, +}); + +// highlight-start +// Retain the S3 bucket on stack deletion +backend.storage.resources.bucket.applyRemovalPolicy(RemovalPolicy.RETAIN); + +// Retain the Cognito user pool on stack deletion +backend.auth.resources.userPool.applyRemovalPolicy(RemovalPolicy.RETAIN); + +// Retain the DynamoDB table on stack deletion +backend.data.resources.cfnResources.amplifyDynamoDbTables["Todo"].applyRemovalPolicy(RemovalPolicy.RETAIN); +// highlight-end +``` From a80352ba707522761eec5f80053ea100da6f25e4 Mon Sep 17 00:00:00 2001 From: ykethan Date: Thu, 24 Oct 2024 15:36:56 -0400 Subject: [PATCH 2/2] rm next-env change --- next-env.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next-env.d.ts b/next-env.d.ts index a4a7b3f5cfa..4f11a03dc6c 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/basic-features/typescript for more information.