From 4e69dda93ec0a45fb98cbf02ac26ce58d844818d Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:25:51 +0900 Subject: [PATCH] feat(rds): support performance insights for cluster --- packages/aws-cdk-lib/aws-rds/lib/cluster.ts | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/aws-cdk-lib/aws-rds/lib/cluster.ts b/packages/aws-cdk-lib/aws-rds/lib/cluster.ts index 515115663b828..0d4a6b3ac4ff2 100644 --- a/packages/aws-cdk-lib/aws-rds/lib/cluster.ts +++ b/packages/aws-cdk-lib/aws-rds/lib/cluster.ts @@ -385,6 +385,27 @@ interface DatabaseClusterBaseProps { * @default - false */ readonly enableDataApi?: boolean; + + /** + * Whether to enable Performance Insights for the DB instance. + * + * @default - false, unless `performanceInsightRetention` or `performanceInsightEncryptionKey` is set. + */ + readonly enablePerformanceInsights?: boolean; + + /** + * The amount of time, in days, to retain Performance Insights data. + * + * @default 7 + */ + readonly performanceInsightRetention?: PerformanceInsightRetention; + + /** + * The AWS KMS key for encryption of Performance Insights data. + * + * @default - default master key + */ + readonly performanceInsightEncryptionKey?: kms.IKey; } /** @@ -690,6 +711,12 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase { }); } + const enablePerformanceInsights = props.enablePerformanceInsights + || props.performanceInsightRetention !== undefined || props.performanceInsightEncryptionKey !== undefined; + if (enablePerformanceInsights && props.enablePerformanceInsights === false) { + throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set'); + } + this.newCfnProps = { // Basic engine: props.engine.engineType, @@ -730,6 +757,11 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase { copyTagsToSnapshot: props.copyTagsToSnapshot ?? true, domain: this.domainId, domainIamRoleName: this.domainRole?.roleName, + performanceInsightsEnabled: enablePerformanceInsights || props.enablePerformanceInsights, // fall back to undefined if not set + performanceInsightsKmsKeyId: props.performanceInsightEncryptionKey?.keyArn, + performanceInsightsRetentionPeriod: enablePerformanceInsights + ? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT) + : undefined, }; }