-
Notifications
You must be signed in to change notification settings - Fork 4.2k
ec2: aws go cdk omits Throughput parameter for EBS block devices #34033
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
Comments
Here is demo to reproduce this issue:
|
Hey @binglius, thank you for reaching out. I was able to reproduce the issue using the following reproduction steps. Reproduction StepsTypeScript Implementation:blockDevices: [
{
deviceName: "/dev/xvda",
volume: cdk.aws_ec2.BlockDeviceVolume.ebs(500, {
volumeType: cdk.aws_ec2.EbsDeviceVolumeType.GP3,
iops: 10000,
throughput: 500 // property
})
}
] Run Generated CloudFormation:BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
Iops: 10000
VolumeSize: 500
VolumeType: gp3
# Throughput parameter is missing WorkaroundAs a workaround, i was able to override the
Generated CloudFormation: BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
Iops: 10000
VolumeSize: 500
VolumeType: gp3
Throughput: 500 Marking this as bug. |
minimal reproducible code import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
export class Issue34033ReproStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create VPC
const vpc = new ec2.Vpc(this, 'VPC', {
maxAzs: 2, // Default is 3, match Go example
subnetConfiguration: [
{
cidrMask: 24,
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC,
},
{
cidrMask: 24,
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
}
]
});
// Define EC2 instance type
const instanceType = ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE);
// Get the latest Amazon Linux 2 AMI
const ami = new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
});
// Define the root block device with specific GP3 settings
const rootBlockDevice: ec2.BlockDevice = {
deviceName: '/dev/xvda', // Standard root device name for Linux AMIs
volume: ec2.BlockDeviceVolume.ebs(100, { // 100 GB size
volumeType: ec2.EbsDeviceVolumeType.GP3,
iops: 6000, // Specific IOPS
throughput: 300, // Specific Throughput (MiB/s)
deleteOnTermination: true,
}),
};
// Create EC2 instance
new ec2.Instance(this, 'EC2Instance', {
vpc: vpc,
instanceType: instanceType,
machineImage: ami,
blockDevices: [rootBlockDevice], // Pass the configured block device
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC, // Place instance in a public subnet for simplicity
},
});
}
} on EC2Instance770AAE32:
Type: AWS::EC2::Instance
Properties:
# ... other properties ...
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
DeleteOnTermination: true
Iops: 6000 # Correctly set
VolumeSize: 100 # Correctly set
VolumeType: gp3 # Correctly set
# Throughput: 300 <-- This property is MISSING
# ... other properties ...
Metadata:
aws:cdk:path: Issue34033ReproStack/EC2Instance/Resource Interesting I don't see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance-ebs.html But CDK does have this prop in the interface. aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/volume.ts Lines 44 to 88 in 74a14b3
Looks like L1 |
In the PR which added the Is it a different use case? |
AWS::EC2::LaunchTemplate Ebs DOES have but AWS::EC2::Instance Ebs does NOT. And they are sharing the same BlockDeviceVolume.ebs using the same BlockDeviceVolume that extends EbsDeviceOptionsBase aws-cdk/packages/aws-cdk-lib/aws-autoscaling/lib/volume.ts Lines 42 to 79 in 74a14b3
![]() |
To improve the developer experience directly within the CDK library and prevent this confusion, we could consider two potential approaches: Option 1: Introduce Type-Specific Interfaces (Breaking Change)
Option 2: Add Synthesis-Time Validation (Non-Breaking)
Both options aim to address the underlying issue and guide users correctly. Option 1 is stricter and safer from a type perspective but introduces a breaking change. Option 2 is less disruptive but relies on runtime (synthesis-time) validation. |
Hi @ykethan, I' building an automate benchmark solution, I'm afraid this workaround doesn't suite my use case. I'll wait for an official solution.
|
Hey @binglius, no worries. wanted to summarize the information and the potential workaround for this issue. import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
export class MyProjectStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create VPC
const vpc = new cdk.aws_ec2.Vpc(this, "TestVpc", {
maxAzs: 2,
natGateways: 0,
});
// Create Launch Template with EBS volume configuration
const launchTemplate = new cdk.aws_ec2.LaunchTemplate(
this,
"TestLaunchTemplate",
{
launchTemplateName: "test-launch-template",
instanceType: cdk.aws_ec2.InstanceType.of(
cdk.aws_ec2.InstanceClass.T3,
cdk.aws_ec2.InstanceSize.LARGE
),
machineImage: new cdk.aws_ec2.AmazonLinuxImage({
generation: cdk.aws_ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
blockDevices: [
{
deviceName: "/dev/xvda",
volume: cdk.aws_ec2.BlockDeviceVolume.ebs(500, {
volumeType: cdk.aws_ec2.EbsDeviceVolumeType.GP3,
iops: 10000,
throughput: 800, // This will work with Launch Template
}),
},
],
}
);
// Create EC2 instance using Launch Template
new cdk.aws_ec2.CfnInstance(this, "TestInstance", {
launchTemplate: {
launchTemplateId: launchTemplate.launchTemplateId,
version: launchTemplate.latestVersionNumber,
},
subnetId: vpc.publicSubnets[0].subnetId,
});
}
} Could you let us know if this could potentially fix the issue for your use case while the team streamlines this experience? |
Hi @ykethan, Thank you for the information, yes the Launch Template works. I prefer awsec2.NewInstance() + Launch template solution(not awsec2.NewCfnInstance() + Launch template), because the awsec2.NewInstance() provides a higher level interface. I was able to do the same in go, but I had to forcibly delete the original network properties Otherwise it fails with following errors. Not sure if there is some better solutions.
Workaround, forcibly delete the network properties.
Here is my code by using Launch Template to support EFA/EnaExpress and EBS Throughput
|
…34571) ### Issue # (if applicable) Closes #34033. ### Reason for this change The throughput property for GP3 volumes is not supported on EC2 instances and only works with Launch Templates. This causes confusion for users who try to set throughput on EC2 instance block devices, as the property is silently ignored. ### Description of changes Added synthesis-time validation in the instanceBlockDeviceMappings function to detect when throughput is specified for an EBS volume on an EC2 instance. The validation throws a clear error message directing users to use Launch Templates instead. ### Describe any new or updated permissions being added No new or updated IAM permissions are needed. ### Description of how you validated changes Added a unit test that verifies the validation works correctly by attempting to create an EC2 instance with a GP3 volume that has throughput specified and confirming that the expected error message is thrown. ### 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*
Comments on closed issues and PRs are hard for our team to see. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I encounter an issue, When running cdk synth, the generated CloudFormation template lacks the Throughput parameter for EBS block devices, even though it is explicitly configured in the code. For example, the template should include:
Here, my code.
The source file indicates it's supported.
https://github.com/aws/aws-cdk-go/blob/awscdk/v2.187.0/awscdk/awsec2/EbsDeviceOptions.go#L33
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
Create EC2 with specified EBS throughput.
Current Behavior
The EBS Size/IOPS are correct, but the throughput stays at 125M/s, the default value.
Reproduction Steps
Create ec2 with blockdevices and ebsOptions below.
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.1007.0
Framework Version
No response
Node.js Version
v22.14.0
OS
MacOS/Gentoo Linux/Amazon Linux
Language
Go
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: