Skip to content

(aws-cdk-lib/core): Size Type Transformation Results in Confusing Model Validation Error #34093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
camerondurham opened this issue Apr 9, 2025 · 1 comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. p2

Comments

@camerondurham
Copy link

camerondurham commented Apr 9, 2025

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:
    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:
const snapshotVolume = new ServiceManagedVolume(this, 'Volume', {
    name: 'volume',
    managedEBSVolume: {
        size: Size.gibibytes(maxShardSizeGiB * 2 * 1.1), // Results in floating-point
        // ...
    },
});
  1. Synthesize the stack
  2. Deploy the stack
  3. 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

@camerondurham camerondurham added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 9, 2025
@github-actions github-actions bot added the @aws-cdk/aws-cloudformation Related to AWS CloudFormation label Apr 9, 2025
@pahud pahud self-assigned this Apr 9, 2025
@pahud
Copy link
Contributor

pahud commented Apr 10, 2025

Hi @camerondurham,

Thank you for your detailed bug report!

You've correctly identified the root cause: CDK currently allows floating-point values for the size property of an EBS volume, which results in CloudFormation runtime validation failures due to non-integer values like 193.60000000000002. This is synthesized directly into the CloudFormation template without rounding or validation, leading to confusing deployment errors.

We agree this should be caught or handled earlier in the development lifecycle.

Next steps:

  • We will explore adding validation or automatic rounding inside CDK to ensure that only integer values are passed to CloudFormation.
  • Ideally, CDK would apply something like Math.ceil() automatically on your behalf or throw a descriptive error at build time.

For now, your workaround — manually wrapping the float calculation in Math.ceil() — is the recommended approach.

We welcome PRs if you'd like to contribute this improvement! Based on your report, the ideal places to add this fix would be either in the Size.gibibytes method or on the EBS volume construct itself, just before synthesis.

Thanks again for helping us improve the AWS CDK developer experience!

@pahud pahud added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2025
@pahud pahud removed their assignment Apr 10, 2025
@pahud pahud added needs-triage This issue or PR still needs to be triaged. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. p2
Projects
None yet
Development

No branches or pull requests

2 participants