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
:
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:
- Automatically round up floating-point values using
Math.ceil
- Throw a build-time validation error when non-integer values are provided
- Automatically round up floating-point values using
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
- Create a
ServiceManagedVolume
with a calculated size that results in a floating-point number:
const snapshotVolume = new ServiceManagedVolume(this, 'Volume', {
name: 'volume',
managedEBSVolume: {
size: Size.gibibytes(maxShardSizeGiB * 2 * 1.1), // Results in floating-point
// ...
},
});
- Synthesize the stack
- Deploy the stack
- Observe CloudFormation deployment failure
Generated CloudFormation
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