Skip to content

Conversation

@badmintoncryer
Copy link
Contributor

Issue # (if applicable)

None

Reason for this change

AWS EBS now supports for specifying volume initialization rate but AWS CDK cannot configure this parameter.

Description of changes

  • Add volumeInitializationRate to VolumeProps

Describe any new or updated permissions being added

none

Description of how you validated changes

Add both unit and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label May 28, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team May 28, 2025 15:04
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label May 28, 2025
@badmintoncryer badmintoncryer changed the title feat(ec2): volume initialization rate feat(ec2): volume initialization rate for EBS volume May 29, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label May 29, 2025
Comment on lines 43 to 47
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistake. I've reverted now.

@aemada-aws aemada-aws self-assigned this May 30, 2025
}

if (!props.volumeInitializationRate.isUnresolved()) {
const rateMiBs = props.volumeInitializationRate.toBytes() / (1024 * 1024);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const rateMiBs = props.volumeInitializationRate.toBytes() / (1024 * 1024);
const rateMiBs = props.volumeInitializationRate.toMebibytes();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment, I think this is not worked for the Size less than 1 MiB.

volumeInitializationRate: rate,
snapshotId: 'snap-0123456789abcdefABCDEF',
});
}).toThrow(`volumeInitializationRate must be between 100 and 300 MiB/s, got: ${rate.toBytes() / (1024 * 1024)} MiB/s`);
Copy link
Contributor

@aemada-aws aemada-aws Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).toThrow(`volumeInitializationRate must be between 100 and 300 MiB/s, got: ${rate.toBytes() / (1024 * 1024)} MiB/s`);
}).toThrow(`volumeInitializationRate must be between 100 and 300 MiB/s, got: ${rate.toMebibytes()} MiB/s`);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code is not worked for the Size less than 1 MiB.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't it? internally it does the same thing

  public static readonly Mebibytes = new StorageUnit('mebibytes', 1024 * 1024);
function convert(amount: number, fromUnit: StorageUnit, toUnit: StorageUnit, options: SizeConversionOptions = {}) {
  const rounding = options.rounding ?? SizeRoundingBehavior.FAIL;
  if (fromUnit.inBytes === toUnit.inBytes) { return amount; }
  if (Token.isUnresolved(amount)) {
    throw new Error(`Size must be specified as 'Size.${toUnit}()' here since its value comes from a token and cannot be converted (got Size.${fromUnit})`);
  }

  const multiplier = fromUnit.inBytes / toUnit.inBytes;
  const value = amount * multiplier;
  switch (rounding) {
    case SizeRoundingBehavior.NONE:
      return value;
    case SizeRoundingBehavior.FLOOR:
      return Math.floor(value);
    default:
    case SizeRoundingBehavior.FAIL:
      if (!Number.isInteger(value)) {
        throw new Error(`'${amount} ${fromUnit}' cannot be converted into a whole number of ${toUnit}.`);
      }
      return value;
  }
}

Copy link
Contributor Author

@badmintoncryer badmintoncryer Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for the lack of clarity.

When a value of 1MiB or more is input, an intuitive error message is returned, but otherwise only '${amount} ${fromUnit}' cannot be converted into a whole number of ${toUnit}. is returned, making it difficult for users to understand where the problem lies.

I think it is better to display

volumeInitializationRate must be between 100 and 300 MiB/s, got: 0.5 MiB/s

than

'${amount} ${fromUnit}' cannot be converted into a whole number of ${toUnit}..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SizeRoundingBehavior should allow you to modify that, the default is fail.

toMebibytes({ rounding: SizeRoundingBehavior.NONE })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for nice information. I've updated to use it.

@mergify
Copy link
Contributor

mergify bot commented Jun 4, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 527d483 into aws:main Jun 4, 2025
17 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 76c698a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@badmintoncryer badmintoncryer deleted the initialization-rate branch September 24, 2025 15:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants