Skip to content

Commit

Permalink
fix(rds): serverlessV2MaxCapacity can be set to 0.5, which is invalid (
Browse files Browse the repository at this point in the history
…#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.

<img width="854" alt="image" src="https://github.com/user-attachments/assets/37c127d8-cd5d-4e88-a699-dff7929a8b95">




### 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*
  • Loading branch information
mazyu36 authored Dec 7, 2024
1 parent ce3598b commit 3fe229d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 2 additions & 5 deletions packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 '+
Expand Down
5 changes: 2 additions & 3 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/],
Expand Down

0 comments on commit 3fe229d

Please sign in to comment.