@@ -116,6 +116,7 @@ Create an OpenSearch instance with encryption.
116
116
``` ts title="amplify/backend.ts"
117
117
// highlight-start
118
118
import * as opensearch from ' aws-cdk-lib/aws-opensearchservice' ;
119
+ import { RemovalPolicy } from " aws-cdk-lib" ;
119
120
// highlight-end
120
121
import { defineBackend } from ' @aws-amplify/backend' ;
121
122
import { auth } from ' ./auth/resource' ;
@@ -148,13 +149,23 @@ const openSearchDomain = new opensearch.Domain(
148
149
{
149
150
version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
150
151
nodeToNodeEncryption: true ,
152
+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
153
+ removalPolicy: RemovalPolicy .DESTROY ,
151
154
encryptionAtRest: {
152
155
enabled: true
153
156
}
154
157
}
155
158
);
156
159
// highlight-end
157
160
```
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
+
158
169
159
170
## Step 3: Setting Up Zero ETL from DynamoDB to OpenSearch
160
171
@@ -181,6 +192,7 @@ Get the `s3BucketArn` and `s3BucketName` values from storage resource as shown b
181
192
``` ts title="amplify/backend.ts"
182
193
import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
183
194
import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
195
+ import { RemovalPolicy } from " aws-cdk-lib" ;
184
196
// highlight-next-line
185
197
import * as iam from " aws-cdk-lib/aws-iam" ;
186
198
import { defineBackend } from " @aws-amplify/backend" ;
@@ -220,6 +232,8 @@ const openSearchDomain = new opensearch.Domain(
220
232
{
221
233
version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
222
234
nodeToNodeEncryption: true ,
235
+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
236
+ removalPolicy: RemovalPolicy .DESTROY ,
223
237
encryptionAtRest: {
224
238
enabled: true ,
225
239
},
@@ -307,6 +321,7 @@ Customize the `template_content` JSON-representation to define the data structur
307
321
``` ts title="amplify/backend.ts"
308
322
import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
309
323
import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
324
+ import { RemovalPolicy } from " aws-cdk-lib" ;
310
325
import * as iam from " aws-cdk-lib/aws-iam" ;
311
326
import { defineBackend } from " @aws-amplify/backend" ;
312
327
import { auth } from " ./auth/resource" ;
@@ -342,6 +357,8 @@ const openSearchDomain = new opensearch.Domain(
342
357
{
343
358
version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
344
359
nodeToNodeEncryption: true ,
360
+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
361
+ removalPolicy: RemovalPolicy .DESTROY ,
345
362
encryptionAtRest: {
346
363
enabled: true ,
347
364
},
@@ -444,6 +461,7 @@ The configuration is a data-prepper feature of OpenSearch. For specific document
444
461
``` ts title="amplify/backend.ts"
445
462
import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
446
463
import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
464
+ import { RemovalPolicy } from " aws-cdk-lib" ;
447
465
import * as iam from " aws-cdk-lib/aws-iam" ;
448
466
import { defineBackend } from " @aws-amplify/backend" ;
449
467
import { auth } from " ./auth/resource" ;
@@ -479,6 +497,8 @@ const openSearchDomain = new opensearch.Domain(
479
497
{
480
498
version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
481
499
nodeToNodeEncryption: true ,
500
+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
501
+ removalPolicy: RemovalPolicy .DESTROY ,
482
502
encryptionAtRest: {
483
503
enabled: true ,
484
504
},
@@ -636,6 +656,7 @@ Now, create the OSIS pipeline resource:
636
656
``` ts title="amplify/backend.ts"
637
657
import * as dynamodb from " aws-cdk-lib/aws-dynamodb" ;
638
658
import * as opensearch from " aws-cdk-lib/aws-opensearchservice" ;
659
+ import { RemovalPolicy } from " aws-cdk-lib" ;
639
660
import * as iam from " aws-cdk-lib/aws-iam" ;
640
661
// highlight-start
641
662
import * as osis from " aws-cdk-lib/aws-osis" ;
@@ -676,6 +697,8 @@ const openSearchDomain = new opensearch.Domain(
676
697
{
677
698
version: opensearch .EngineVersion .OPENSEARCH_2_11 ,
678
699
nodeToNodeEncryption: true ,
700
+ // set removalPolicy to DESTROY to make sure the open search domain is deleted on stack deletion.
701
+ removalPolicy: RemovalPolicy .DESTROY ,
679
702
encryptionAtRest: {
680
703
enabled: true ,
681
704
},
0 commit comments