Skip to content

Commit

Permalink
feat: Add configurable ddb delete protection
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhidir-aws committed Feb 18, 2025
1 parent 29eda0b commit 2c3741d
Show file tree
Hide file tree
Showing 11 changed files with 10,244 additions and 5,633 deletions.
10 changes: 10 additions & 0 deletions cli/magic-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const embeddingModels: ModelConfig[] = [
options.prefix = config.prefix;
options.createCMKs = config.createCMKs;
options.retainOnDelete = config.retainOnDelete;
options.ddbDeletionProtection = config.ddbDeletionProtection;
options.vpcId = config.vpc?.vpcId;
options.bedrockEnable = config.bedrock?.enabled;
options.bedrockRegion = config.bedrock?.region;
Expand Down Expand Up @@ -321,6 +322,14 @@ async function processCreateOptions(options: any): Promise<void> {
initial: options.retainOnDelete ?? true,
hint: "It reduces the risk of deleting data. It will however not delete all the resources on cleanup (would require manual removal if relevant)",
},
{
type: "confirm",
name: "ddbDeletionProtection",
message:
"Do you want to enable delete protection for your DynamoDB tables?",
initial: options.ddbDeletionProtection ?? false,
hint: "It reduces the risk of accidental deleting your DDB tables. It will however not delete your DDB tables on cleanup.",
},
{
type: "confirm",
name: "bedrockEnable",
Expand Down Expand Up @@ -1200,6 +1209,7 @@ async function processCreateOptions(options: any): Promise<void> {
prefix: answers.prefix,
createCMKs: answers.createCMKs,
retainOnDelete: answers.retainOnDelete,
ddbDeletionProtection: answers.ddbDeletionProtection,
vpc: answers.existingVpc
? {
vpcId: answers.vpcId.toLowerCase(),
Expand Down
2 changes: 2 additions & 0 deletions lib/chatbot-api/application-dynamodb-tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as kms from "aws-cdk-lib/aws-kms";

export interface ApplicationDynamoDBTablesProps {
readonly retainOnDelete?: boolean;
readonly deletionProtection?: boolean;
readonly kmsKey?: kms.Key;
}

Expand Down Expand Up @@ -33,6 +34,7 @@ export class ApplicationDynamoDBTables extends Construct {
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
: cdk.RemovalPolicy.DESTROY,
pointInTimeRecovery: true,
deletionProtection: props.deletionProtection,
});

this.applicationTable = applicationTable;
Expand Down
2 changes: 2 additions & 0 deletions lib/chatbot-api/chatbot-dynamodb-tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as kms from "aws-cdk-lib/aws-kms";

export interface ChatBotDynamoDBTablesProps {
readonly retainOnDelete?: boolean;
readonly deletionProtection?: boolean;
readonly kmsKey?: kms.Key;
}

Expand Down Expand Up @@ -34,6 +35,7 @@ export class ChatBotDynamoDBTables extends Construct {
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
: cdk.RemovalPolicy.DESTROY,
pointInTimeRecovery: true,
deletionProtection: props.deletionProtection,
});

sessionsTable.addGlobalSecondaryIndex({
Expand Down
2 changes: 2 additions & 0 deletions lib/chatbot-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ChatBotApi extends Construct {
const chatTables = new ChatBotDynamoDBTables(this, "ChatDynamoDBTables", {
kmsKey: props.shared.kmsKey,
retainOnDelete: props.config.retainOnDelete,
deletionProtection: props.config.ddbDeletionProtection,
});
const chatBuckets = new ChatBotS3Buckets(this, "ChatBuckets", {
kmsKey: props.shared.kmsKey,
Expand All @@ -60,6 +61,7 @@ export class ChatBotApi extends Construct {
{
kmsKey: props.shared.kmsKey,
retainOnDelete: props.config.retainOnDelete,
deletionProtection: props.config.ddbDeletionProtection,
}
);
const loggingRole = new iam.Role(this, "apiLoggingRole", {
Expand Down
1 change: 1 addition & 0 deletions lib/rag-engines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class RagEngines extends Construct {
const tables = new RagDynamoDBTables(this, "RagDynamoDBTables", {
kmsKey: props.shared.kmsKey,
retainOnDelete: props.config.retainOnDelete,
deletionProtection: props.config.ddbDeletionProtection,
});

let sageMakerRagModels: SageMakerRagModels | null = null;
Expand Down
3 changes: 3 additions & 0 deletions lib/rag-engines/rag-dynamodb-tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Construct } from "constructs";

export interface RagDynamoDBTablesProps {
readonly retainOnDelete?: boolean;
readonly deletionProtection?: boolean;
readonly kmsKey?: kms.Key;
}

Expand Down Expand Up @@ -39,6 +40,7 @@ export class RagDynamoDBTables extends Construct {
props.retainOnDelete === true
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
: cdk.RemovalPolicy.DESTROY,
deletionProtection: props.deletionProtection,
});

workspacesTable.addGlobalSecondaryIndex({
Expand Down Expand Up @@ -72,6 +74,7 @@ export class RagDynamoDBTables extends Construct {
props.retainOnDelete === true
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE
: cdk.RemovalPolicy.DESTROY,
deletionProtection: props.deletionProtection,
});

documentsTable.addGlobalSecondaryIndex({
Expand Down
1 change: 1 addition & 0 deletions lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface SystemConfig {
prefix: string;
createCMKs?: boolean;
retainOnDelete?: boolean;
ddbDeletionProtection?: boolean;
vpc?: {
vpcId?: string;
createVpcEndpoints?: boolean;
Expand Down
Loading

0 comments on commit 2c3741d

Please sign in to comment.