Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/lib/private/ebs-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { CfnInstance, CfnLaunchTemplate } from '../ec2.generated';
import { BlockDevice, EbsDeviceVolumeType } from '../volume';

export function instanceBlockDeviceMappings(construct: Construct, blockDevices: BlockDevice[]): CfnInstance.BlockDeviceMappingProperty[] {
for (const blockDevice of blockDevices) {
if (blockDevice.volume.ebsDevice?.throughput !== undefined) {
Annotations.of(construct).addWarningV2('@aws-cdk/aws-ec2:throughputNotSupported',
'The throughput property is not supported on EC2 instances. Use a Launch Template instead. ' +
'See https://github.com/aws/aws-cdk/issues/34033 for more information.',
);
}
}
return synthesizeBlockDeviceMappings<CfnInstance.BlockDeviceMappingProperty, object>(construct, blockDevices, {});
}

Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ describe('instance', () => {
});
});

test('warns if throughput is specified for an EBS volume', () => {
// WHEN
new Instance(stack, 'Instance', {
vpc,
machineImage: new AmazonLinuxImage(),
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),
blockDevices: [{
deviceName: 'ebs',
volume: BlockDeviceVolume.ebs(15, {
deleteOnTermination: true,
encrypted: true,
volumeType: EbsDeviceVolumeType.GP3,
throughput: 125,
}),
}],
});
// THEN
Annotations.fromStack(stack).hasWarning('/Default/Instance', Match.stringLikeRegexp('The throughput property is not supported on EC2 instances. Use a Launch Template instead'));
});

test('throws if ephemeral volumeIndex < 0', () => {
// THEN
expect(() => {
Expand Down
Loading