@@ -116,6 +116,7 @@ Create an OpenSearch instance with encryption.
116116``` ts title="amplify/backend.ts"
117117// highlight-start
118118import * as opensearch from ' aws-cdk-lib/aws-opensearchservice' ;
119+ import { RemovalPolicy } from " aws-cdk-lib" ;
119120// highlight-end
120121import { defineBackend } from ' @aws-amplify/backend' ;
121122import { auth } from ' ./auth/resource' ;
@@ -148,13 +149,23 @@ const openSearchDomain = new opensearch.Domain(
148149 {
149150 version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
150151 nodeToNodeEncryption: true ,
152+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
153+ removalPolicy: RemovalPolicy .DESTROY ,
151154 encryptionAtRest: {
152155 enabled: true
153156 }
154157 }
155158);
156159// highlight-end
157160```
161+ <Callout warning >
162+
163+ ** Important considerations:**
164+
165+ We recommend configuring the ` removalPolicy ` to destroy resources for sandbox environments. By default, OpenSearch instances are not deleted when you run ` npx ampx sandbox delete ` , as the default removal policy for stateful resources is set to retain the resource.
166+
167+ </Callout >
168+
158169
159170## Step 3: Setting Up Zero ETL from DynamoDB to OpenSearch
160171
@@ -181,6 +192,7 @@ Get the `s3BucketArn` and `s3BucketName` values from storage resource as shown b
181192``` ts title="amplify/backend.ts"
182193import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
183194import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
195+ import { RemovalPolicy } from " aws-cdk-lib" ;
184196// highlight-next-line
185197import * as iam from " aws-cdk-lib/aws-iam" ;
186198import { defineBackend } from " @aws-amplify/backend" ;
@@ -220,6 +232,8 @@ const openSearchDomain = new opensearch.Domain(
220232 {
221233 version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
222234 nodeToNodeEncryption: true ,
235+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
236+ removalPolicy: RemovalPolicy .DESTROY ,
223237 encryptionAtRest: {
224238 enabled: true ,
225239 },
@@ -307,6 +321,7 @@ Customize the `template_content` JSON-representation to define the data structur
307321``` ts title="amplify/backend.ts"
308322import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
309323import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
324+ import { RemovalPolicy } from " aws-cdk-lib" ;
310325import * as iam from " aws-cdk-lib/aws-iam" ;
311326import { defineBackend } from " @aws-amplify/backend" ;
312327import { auth } from " ./auth/resource" ;
@@ -342,6 +357,8 @@ const openSearchDomain = new opensearch.Domain(
342357 {
343358 version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
344359 nodeToNodeEncryption: true ,
360+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
361+ removalPolicy: RemovalPolicy .DESTROY ,
345362 encryptionAtRest: {
346363 enabled: true ,
347364 },
@@ -444,6 +461,7 @@ The configuration is a data-prepper feature of OpenSearch. For specific document
444461``` ts title="amplify/backend.ts"
445462import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
446463import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
464+ import { RemovalPolicy } from " aws-cdk-lib" ;
447465import * as iam from " aws-cdk-lib/aws-iam" ;
448466import { defineBackend } from " @aws-amplify/backend" ;
449467import { auth } from " ./auth/resource" ;
@@ -479,6 +497,8 @@ const openSearchDomain = new opensearch.Domain(
479497 {
480498 version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
481499 nodeToNodeEncryption: true ,
500+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
501+ removalPolicy: RemovalPolicy .DESTROY ,
482502 encryptionAtRest: {
483503 enabled: true ,
484504 },
@@ -636,6 +656,7 @@ Now, create the OSIS pipeline resource:
636656``` ts title="amplify/backend.ts"
637657import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
638658import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
659+ import { RemovalPolicy } from " aws-cdk-lib" ;
639660import * as iam from " aws-cdk-lib/aws-iam" ;
640661// highlight-start
641662import * as osis from " aws-cdk-lib/aws-osis" ;
@@ -676,6 +697,8 @@ const openSearchDomain = new opensearch.Domain(
676697 {
677698 version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
678699 nodeToNodeEncryption: true ,
700+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
701+ removalPolicy: RemovalPolicy .DESTROY ,
679702 encryptionAtRest: {
680703 enabled: true ,
681704 },
0 commit comments