(aws-cdk-lib/core): Size Type Transformation Results in Confusing Model Validation Error
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When creating an EBS volume using `ServiceManagedVolume`, floating-point values for the `size` parameter are not automatically rounded, leading to CloudFormation deployment/validation failures that are difficult to debug. I believe the issue occurs because CloudFormation expects integer values for `SizeInGiB`, but floating-point numbers in the synthesized YAML are interpreted as strings.
The root cause here seemed to be that CDK generated a config value `SizeInGiB: 193.60000000000002` which the API model expected to be a number but the `193.60000000000002` value was treated as a string. Can this be an error or warning at build time instead?
## Workaround
Manually wrap the size calculation in `Math.ceil`:
```typescript
size: Size.gibibytes(Math.ceil(maxShardSizeGiB * 2 * 1.1))
```
## Additional Context
- This validation would improve developer experience by catching the issue earlier in the development cycle
- Similar validation might be useful for other numeric CloudFormation properties that require integers
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
- Add validation (somewhere) in the CDK library to ensure sizes are integers
- Either:
1. Automatically round up floating-point values using `Math.ceil`
2. Throw a build-time validation error when non-integer values are provided
### Current Behavior
- Floating-point values for sizes (in this example, EBS volume sizes) are allowed and synthesized directly to CloudFormation
- This results in runtime deployment failures with cryptic error messages
- The error is not caught during build time or by `cfn-lint`
Error Message During Deployment
```
Resource handler returned message: "Model validation failed (#/VolumeConfigurations/0/ManagedEBSVolume/SizeInGiB: expected type: Integer, found: String)" ...
```
### Reproduction Steps
1. Create a `ServiceManagedVolume` with a calculated size that results in a floating-point number:
```typescript
const snapshotVolume = new ServiceManagedVolume(this, 'Volume', {
name: 'volume',
managedEBSVolume: {
size: Size.gibibytes(maxShardSizeGiB * 2 * 1.1), // Results in floating-point
// ...
},
});
```
2. Synthesize the stack
3. Deploy the stack
4. Observe CloudFormation deployment failure
## Generated CloudFormation
```yaml
VolumeConfigurations:
- ManagedEBSVolume:
Encrypted: true
FilesystemType: xfs
SizeInGiB: 193.60000000000002 # Should be an integer
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.1007.0
### Framework Version
2.139.0
### Node.js Version
NodeJS 18
### OS
Linux
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Begin at the ServiceManagedVolume managedEBSVolume size path and the Size.gibibytes API described in the report; reproduce the synthesized SizeInGiB value using the supplied calculation. Done means the chosen behavior—integer rounding or build-time validation—is defined and the floating-point input no longer reaches CloudFormation as an invalid SizeInGiB value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100