Skip to content

Commit 14ba709

Browse files
feat: Add configurable ddb delete protection (#633)
Co-authored-by: Maryam Khidir <mkhidir@amazon.de>
1 parent 29eda0b commit 14ba709

File tree

20 files changed

+11187
-11911
lines changed

20 files changed

+11187
-11911
lines changed

cli/magic-config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const embeddingModels: ModelConfig[] = [
154154
options.prefix = config.prefix;
155155
options.createCMKs = config.createCMKs;
156156
options.retainOnDelete = config.retainOnDelete;
157+
options.ddbDeletionProtection = config.ddbDeletionProtection;
157158
options.vpcId = config.vpc?.vpcId;
158159
options.bedrockEnable = config.bedrock?.enabled;
159160
options.bedrockRegion = config.bedrock?.region;
@@ -321,6 +322,14 @@ async function processCreateOptions(options: any): Promise<void> {
321322
initial: options.retainOnDelete ?? true,
322323
hint: "It reduces the risk of deleting data. It will however not delete all the resources on cleanup (would require manual removal if relevant)",
323324
},
325+
{
326+
type: "confirm",
327+
name: "ddbDeletionProtection",
328+
message:
329+
"Do you want to enable delete protection for your DynamoDB tables?",
330+
initial: options.ddbDeletionProtection ?? false,
331+
hint: "It reduces the risk of accidental deleting your DDB tables. It will however not delete your DDB tables on cleanup.",
332+
},
324333
{
325334
type: "confirm",
326335
name: "bedrockEnable",
@@ -1200,6 +1209,7 @@ async function processCreateOptions(options: any): Promise<void> {
12001209
prefix: answers.prefix,
12011210
createCMKs: answers.createCMKs,
12021211
retainOnDelete: answers.retainOnDelete,
1212+
ddbDeletionProtection: answers.ddbDeletionProtection,
12031213
vpc: answers.existingVpc
12041214
? {
12051215
vpcId: answers.vpcId.toLowerCase(),

lib/chatbot-api/application-dynamodb-tables/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as kms from "aws-cdk-lib/aws-kms";
55

66
export interface ApplicationDynamoDBTablesProps {
77
readonly retainOnDelete?: boolean;
8+
readonly deletionProtection?: boolean;
89
readonly kmsKey?: kms.Key;
910
}
1011

@@ -33,6 +34,7 @@ export class ApplicationDynamoDBTables extends Construct {
3334
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
3435
: cdk.RemovalPolicy.DESTROY,
3536
pointInTimeRecovery: true,
37+
deletionProtection: props.deletionProtection,
3638
});
3739

3840
this.applicationTable = applicationTable;

lib/chatbot-api/chatbot-dynamodb-tables/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as kms from "aws-cdk-lib/aws-kms";
55

66
export interface ChatBotDynamoDBTablesProps {
77
readonly retainOnDelete?: boolean;
8+
readonly deletionProtection?: boolean;
89
readonly kmsKey?: kms.Key;
910
}
1011

@@ -34,6 +35,7 @@ export class ChatBotDynamoDBTables extends Construct {
3435
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
3536
: cdk.RemovalPolicy.DESTROY,
3637
pointInTimeRecovery: true,
38+
deletionProtection: props.deletionProtection,
3739
});
3840

3941
sessionsTable.addGlobalSecondaryIndex({

lib/chatbot-api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class ChatBotApi extends Construct {
4949
const chatTables = new ChatBotDynamoDBTables(this, "ChatDynamoDBTables", {
5050
kmsKey: props.shared.kmsKey,
5151
retainOnDelete: props.config.retainOnDelete,
52+
deletionProtection: props.config.ddbDeletionProtection,
5253
});
5354
const chatBuckets = new ChatBotS3Buckets(this, "ChatBuckets", {
5455
kmsKey: props.shared.kmsKey,
@@ -60,6 +61,7 @@ export class ChatBotApi extends Construct {
6061
{
6162
kmsKey: props.shared.kmsKey,
6263
retainOnDelete: props.config.retainOnDelete,
64+
deletionProtection: props.config.ddbDeletionProtection,
6365
}
6466
);
6567
const loggingRole = new iam.Role(this, "apiLoggingRole", {

lib/rag-engines/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class RagEngines extends Construct {
4141
const tables = new RagDynamoDBTables(this, "RagDynamoDBTables", {
4242
kmsKey: props.shared.kmsKey,
4343
retainOnDelete: props.config.retainOnDelete,
44+
deletionProtection: props.config.ddbDeletionProtection,
4445
});
4546

4647
let sageMakerRagModels: SageMakerRagModels | null = null;

lib/rag-engines/rag-dynamodb-tables/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Construct } from "constructs";
55

66
export interface RagDynamoDBTablesProps {
77
readonly retainOnDelete?: boolean;
8+
readonly deletionProtection?: boolean;
89
readonly kmsKey?: kms.Key;
910
}
1011

@@ -39,6 +40,7 @@ export class RagDynamoDBTables extends Construct {
3940
props.retainOnDelete === true
4041
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
4142
: cdk.RemovalPolicy.DESTROY,
43+
deletionProtection: props.deletionProtection,
4244
});
4345

4446
workspacesTable.addGlobalSecondaryIndex({
@@ -72,6 +74,7 @@ export class RagDynamoDBTables extends Construct {
7274
props.retainOnDelete === true
7375
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
7476
: cdk.RemovalPolicy.DESTROY,
77+
deletionProtection: props.deletionProtection,
7578
});
7679

7780
documentsTable.addGlobalSecondaryIndex({

lib/shared/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ export class Shared extends Construct {
194194
) {
195195
if (props.config.bedrock?.region !== cdk.Stack.of(this).region) {
196196
throw new Error(
197-
`Bedrock is only supported in the same region as the stack when using private website (Bedrock region: ${props
198-
.config.bedrock?.region}, Stack region: ${
199-
cdk.Stack.of(this).region
200-
}).`
197+
`Bedrock is only supported in the same region as the stack when using private website (Bedrock region: ${
198+
props.config.bedrock?.region
199+
}, Stack region: ${cdk.Stack.of(this).region}).`
201200
);
202201
}
203202

lib/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface SystemConfig {
8181
prefix: string;
8282
createCMKs?: boolean;
8383
retainOnDelete?: boolean;
84+
ddbDeletionProtection?: boolean;
8485
vpc?: {
8586
vpcId?: string;
8687
createVpcEndpoints?: boolean;

0 commit comments

Comments
 (0)