Skip to content

Commit 7ae6559

Browse files
committed
Simplifying KMS alias implementation using addAlias method
1 parent 3df4d12 commit 7ae6559

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

packages/cdk/constructs/DynamoDbTable.ts

Lines changed: 2 additions & 8 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, Alias} from "aws-cdk-lib/aws-kms"
9+
import {Key} from "aws-cdk-lib/aws-kms"
1010

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

2524
constructor(scope: Construct, id: string, props: DynamoDbTableProps) {
2625
super(scope, id)
@@ -30,12 +29,7 @@ export class DynamoDbTable extends Construct {
3029
description: `KMS key for ${props.tableName} DynamoDB table encryption`,
3130
removalPolicy: RemovalPolicy.DESTROY
3231
})
33-
34-
this.kmsAlias = new Alias(this, "TableKeyAlias", {
35-
aliasName: `alias/${props.tableName}-dynamodb-key`,
36-
targetKey: this.kmsKey,
37-
removalPolicy: RemovalPolicy.DESTROY
38-
})
32+
this.kmsKey.addAlias(`alias/${props.tableName}-dynamodb-key`)
3933

4034
this.table = new TableV2(this, props.tableName, {
4135
tableName: props.tableName,

packages/cdk/constructs/S3Bucket.ts

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

1111
export interface S3BucketProps {
1212
readonly bucketName: string
@@ -16,7 +16,6 @@ export interface S3BucketProps {
1616
export class S3Bucket extends Construct {
1717
public readonly bucket: Bucket
1818
public readonly kmsKey: Key
19-
public readonly kmsAlias: Alias
2019

2120
constructor(scope: Construct, id: string, props: S3BucketProps) {
2221
super(scope, id)
@@ -26,12 +25,7 @@ export class S3Bucket extends Construct {
2625
description: `KMS key for ${props.bucketName} S3 bucket encryption`,
2726
removalPolicy: RemovalPolicy.DESTROY
2827
})
29-
30-
this.kmsAlias = new Alias(this, "BucketKeyAlias", {
31-
aliasName: `alias/${props.bucketName}-s3-key`,
32-
targetKey: this.kmsKey,
33-
removalPolicy: RemovalPolicy.DESTROY
34-
})
28+
this.kmsKey.addAlias(`alias/${props.bucketName}-s3-key`)
3529

3630
this.bucket = new Bucket(this, props.bucketName, {
3731
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,

0 commit comments

Comments
 (0)