Skip to content

Commit 69f1ef4

Browse files
committed
Add KMS alias and removal policies for key to DynamoDbTable construct
1 parent 48f161c commit 69f1ef4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/cdk/constructs/DynamoDbTable.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Billing,
77
TableEncryptionV2
88
} from "aws-cdk-lib/aws-dynamodb"
9-
import {Key} from "aws-cdk-lib/aws-kms"
9+
import {Key, Alias} from "aws-cdk-lib/aws-kms"
1010

1111
export interface DynamoDbTableProps {
1212
readonly tableName: string
@@ -20,13 +20,21 @@ export interface DynamoDbTableProps {
2020
export class DynamoDbTable extends Construct {
2121
public readonly table: TableV2
2222
public readonly kmsKey: Key
23+
public readonly kmsAlias: Alias
2324

2425
constructor(scope: Construct, id: string, props: DynamoDbTableProps) {
2526
super(scope, id)
2627

2728
this.kmsKey = new Key(this, "TableKey", {
2829
enableKeyRotation: true,
29-
description: `KMS key for ${props.tableName} DynamoDB table encryption`
30+
description: `KMS key for ${props.tableName} DynamoDB table encryption`,
31+
removalPolicy: RemovalPolicy.DESTROY
32+
})
33+
34+
this.kmsAlias = new Alias(this, "TableKeyAlias", {
35+
aliasName: `alias/${props.tableName}-dynamodb-key`,
36+
targetKey: this.kmsKey,
37+
removalPolicy: RemovalPolicy.DESTROY
3038
})
3139

3240
this.table = new TableV2(this, props.tableName, {

0 commit comments

Comments
 (0)