From 3fe229d0eb48fe405e00bf3717face3c4cfc2cc1 Mon Sep 17 00:00:00 2001 From: Matsuda Date: Sat, 7 Dec 2024 10:13:35 +0900 Subject: [PATCH] fix(rds): serverlessV2MaxCapacity can be set to 0.5, which is invalid (#32232) ### Issue # (if applicable) N/A ### Reason for this change In [CFn docs](https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-rds-dbcluster-serverlessv2scalingconfiguration.html#cfn-rds-dbcluster-serverlessv2scalingconfiguration-maxcapacity), MaximumCapacity value must be higher than 0.5 ACUs. ``` The maximum capacity must be higher than 0.5 ACUs. ``` This means MaximumCapacity cannot be set to 0.5 ACUs. However, in the CDK, `serverlessV2MaxCapacity` can be set to 0.5, which is invalid. When I attempted to deploy with `serverlessV2MaxCapacity` set to 0.5, I encountered the following error: > CREATE_FAILED | AWS::RDS::DBCluster | Integ-Cluster (IntegCluster4261F36F) Resource handler returned message: "Serverless v2 maximum capacity 0.5 isn't valid. The maximum capacity must be at least 1.0. In the Management Console, Maximum Capacity cannot be set to 0.5. image ### Description of changes Fix a validation. ### Description of how you validated changes Fix unit tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk-lib/aws-rds/lib/cluster.ts | 7 ++----- packages/aws-cdk-lib/aws-rds/test/cluster.test.ts | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/aws-cdk-lib/aws-rds/lib/cluster.ts b/packages/aws-cdk-lib/aws-rds/lib/cluster.ts index 3f09f240df96d..48521aedd2a1b 100644 --- a/packages/aws-cdk-lib/aws-rds/lib/cluster.ts +++ b/packages/aws-cdk-lib/aws-rds/lib/cluster.ts @@ -1074,8 +1074,8 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase { } private validateServerlessScalingConfig(): void { - if (this.serverlessV2MaxCapacity > 256 || this.serverlessV2MaxCapacity < 0.5) { - throw new Error('serverlessV2MaxCapacity must be >= 0.5 & <= 256'); + if (this.serverlessV2MaxCapacity > 256 || this.serverlessV2MaxCapacity < 1) { + throw new Error('serverlessV2MaxCapacity must be >= 1 & <= 256'); } if (this.serverlessV2MinCapacity > 256 || this.serverlessV2MinCapacity < 0) { @@ -1086,9 +1086,6 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase { throw new Error('serverlessV2MaxCapacity must be greater than serverlessV2MinCapacity'); } - if (this.serverlessV2MaxCapacity === 0.5 && this.serverlessV2MinCapacity === 0.5) { - throw new Error('If serverlessV2MinCapacity === 0.5 then serverlessV2MaxCapacity must be >=1'); - } const regexp = new RegExp(/^[0-9]+\.?5?$/); if (!regexp.test(this.serverlessV2MaxCapacity.toString()) || !regexp.test(this.serverlessV2MinCapacity.toString())) { throw new Error('serverlessV2MinCapacity & serverlessV2MaxCapacity must be in 0.5 step increments, received '+ diff --git a/packages/aws-cdk-lib/aws-rds/test/cluster.test.ts b/packages/aws-cdk-lib/aws-rds/test/cluster.test.ts index 8091945676ea8..56a426d9cc9ec 100644 --- a/packages/aws-cdk-lib/aws-rds/test/cluster.test.ts +++ b/packages/aws-cdk-lib/aws-rds/test/cluster.test.ts @@ -116,11 +116,10 @@ describe('cluster new api', () => { }); test.each([ - [0.5, 300, /serverlessV2MaxCapacity must be >= 0.5 & <= 256/], - [0.5, 0, /serverlessV2MaxCapacity must be >= 0.5 & <= 256/], + [0.5, 300, /serverlessV2MaxCapacity must be >= 1 & <= 256/], + [0.5, 0, /serverlessV2MaxCapacity must be >= 1 & <= 256/], [-1, 1, /serverlessV2MinCapacity must be >= 0 & <= 256/], [300, 1, /serverlessV2MinCapacity must be >= 0 & <= 256/], - [0.5, 0.5, /If serverlessV2MinCapacity === 0.5 then serverlessV2MaxCapacity must be >=1/], [10.1, 12, /serverlessV2MinCapacity & serverlessV2MaxCapacity must be in 0.5 step increments/], [12, 12.1, /serverlessV2MinCapacity & serverlessV2MaxCapacity must be in 0.5 step increments/], [5, 1, /serverlessV2MaxCapacity must be greater than serverlessV2MinCapacity/],