Skip to content

Commit 78ef388

Browse files
committed
feat: adds gp3 throughput support to asg
resolves: #16213
1 parent 60176b9 commit 78ef388

11 files changed

+544
-29
lines changed

packages/@aws-cdk/aws-autoscaling/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,36 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', {
278278
});
279279
```
280280

281+
### Block Devices
282+
283+
This type specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes.
284+
285+
#### GP3 Volumes
286+
287+
You can only specify the `throughput` on GP3 volumes.
288+
289+
```ts
290+
declare const vpc: ec2.Vpc;
291+
declare const instanceType: ec2.InstanceType;
292+
declare const machineImage: ec2.IMachineImage;
293+
294+
const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
295+
vpc,
296+
instanceType,
297+
machineImage,
298+
blockDevices: [{
299+
{
300+
deviceName: 'gp3-volume',
301+
volume: autoscaling.BlockDeviceVolume.ebs(15, {
302+
volumeType: autoscaling.EbsDeviceVolumeType.GP3,
303+
throughput: 125,
304+
}),
305+
},
306+
}],
307+
// ...
308+
});
309+
```
310+
281311
## Configuring Instances using CloudFormation Init
282312

283313
It is possible to use the CloudFormation Init mechanism to configure the

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,16 @@ function synthesizeBlockDeviceMappings(construct: Construct, blockDevices: Block
21672167
}
21682168

21692169
if (ebs) {
2170-
const { iops, volumeType } = ebs;
2170+
const { iops, volumeType, throughput } = ebs;
2171+
2172+
if (throughput) {
2173+
if (volumeType != EbsDeviceVolumeType.GP3) {
2174+
throw new Error('throughput property requires volumeType: EbsDeviceVolumeType.GP3');
2175+
}
2176+
if (throughput < 125 || throughput > 1000) {
2177+
throw new Error('throughput property takes a minimum of 125 and a maximum of 1000');
2178+
}
2179+
}
21712180

21722181
if (!iops) {
21732182
if (volumeType === EbsDeviceVolumeType.IO1) {

packages/@aws-cdk/aws-autoscaling/lib/volume.ts

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export interface EbsDeviceOptionsBase {
6666
* @default {@link EbsDeviceVolumeType.GP2}
6767
*/
6868
readonly volumeType?: EbsDeviceVolumeType;
69+
70+
/**
71+
* The throughput that the volume supports, in MiB/s
72+
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
73+
* @default - 125 MiB/s
74+
*/
75+
readonly throughput?: number;
6976
}
7077

7178
/**

packages/@aws-cdk/aws-autoscaling/test/asg-lt.integ.snapshot/aws-cdk-asg-integ.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"files": {
4-
"cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b": {
4+
"92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d": {
55
"source": {
66
"path": "aws-cdk-asg-integ.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b.json",
12+
"objectKey": "92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-autoscaling/test/asg-lt.integ.snapshot/aws-cdk-asg-integ.template.json

+138
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,140 @@
625625
"IgnoreUnmodifiedGroupSizeProperties": true
626626
}
627627
}
628+
},
629+
"AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206": {
630+
"Type": "AWS::EC2::SecurityGroup",
631+
"Properties": {
632+
"GroupDescription": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceSecurityGroup",
633+
"SecurityGroupEgress": [
634+
{
635+
"CidrIp": "0.0.0.0/0",
636+
"Description": "Allow all outbound traffic by default",
637+
"IpProtocol": "-1"
638+
}
639+
],
640+
"Tags": [
641+
{
642+
"Key": "Name",
643+
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
644+
}
645+
],
646+
"VpcId": {
647+
"Ref": "VPCB9E5F0B4"
648+
}
649+
}
650+
},
651+
"AsgWithGp3BlockdeviceInstanceRoleF52FB39B": {
652+
"Type": "AWS::IAM::Role",
653+
"Properties": {
654+
"AssumeRolePolicyDocument": {
655+
"Statement": [
656+
{
657+
"Action": "sts:AssumeRole",
658+
"Effect": "Allow",
659+
"Principal": {
660+
"Service": {
661+
"Fn::Join": [
662+
"",
663+
[
664+
"ec2.",
665+
{
666+
"Ref": "AWS::URLSuffix"
667+
}
668+
]
669+
]
670+
}
671+
}
672+
}
673+
],
674+
"Version": "2012-10-17"
675+
},
676+
"Tags": [
677+
{
678+
"Key": "Name",
679+
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
680+
}
681+
]
682+
}
683+
},
684+
"AsgWithGp3BlockdeviceInstanceProfile2FC414A5": {
685+
"Type": "AWS::IAM::InstanceProfile",
686+
"Properties": {
687+
"Roles": [
688+
{
689+
"Ref": "AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
690+
}
691+
]
692+
}
693+
},
694+
"AsgWithGp3BlockdeviceLaunchConfig24411F5E": {
695+
"Type": "AWS::AutoScaling::LaunchConfiguration",
696+
"Properties": {
697+
"ImageId": {
698+
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
699+
},
700+
"InstanceType": "t3.micro",
701+
"BlockDeviceMappings": [
702+
{
703+
"DeviceName": "ebs",
704+
"Ebs": {
705+
"DeleteOnTermination": true,
706+
"Encrypted": true,
707+
"Throughput": 125,
708+
"VolumeSize": 15,
709+
"VolumeType": "gp3"
710+
}
711+
}
712+
],
713+
"IamInstanceProfile": {
714+
"Ref": "AsgWithGp3BlockdeviceInstanceProfile2FC414A5"
715+
},
716+
"SecurityGroups": [
717+
{
718+
"Fn::GetAtt": [
719+
"AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206",
720+
"GroupId"
721+
]
722+
}
723+
],
724+
"UserData": {
725+
"Fn::Base64": "#!/bin/bash"
726+
}
727+
},
728+
"DependsOn": [
729+
"AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
730+
]
731+
},
732+
"AsgWithGp3BlockdeviceASGE82AA487": {
733+
"Type": "AWS::AutoScaling::AutoScalingGroup",
734+
"Properties": {
735+
"MaxSize": "10",
736+
"MinSize": "0",
737+
"DesiredCapacity": "5",
738+
"LaunchConfigurationName": {
739+
"Ref": "AsgWithGp3BlockdeviceLaunchConfig24411F5E"
740+
},
741+
"Tags": [
742+
{
743+
"Key": "Name",
744+
"PropagateAtLaunch": true,
745+
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
746+
}
747+
],
748+
"VPCZoneIdentifier": [
749+
{
750+
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
751+
},
752+
{
753+
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
754+
}
755+
]
756+
},
757+
"UpdatePolicy": {
758+
"AutoScalingScheduledAction": {
759+
"IgnoreUnmodifiedGroupSizeProperties": true
760+
}
761+
}
628762
}
629763
},
630764
"Parameters": {
@@ -636,6 +770,10 @@
636770
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
637771
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-arm64-gp2"
638772
},
773+
"SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
774+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
775+
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
776+
},
639777
"BootstrapVersion": {
640778
"Type": "AWS::SSM::Parameter::Value<String>",
641779
"Default": "/cdk-bootstrap/hnb659fds/version",
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"21.0.0"}

packages/@aws-cdk/aws-autoscaling/test/asg-lt.integ.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"testCases": {
44
"integ.asg-lt": {
55
"stacks": [

packages/@aws-cdk/aws-autoscaling/test/asg-lt.integ.snapshot/manifest.json

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"artifacts": {
44
"Tree": {
55
"type": "cdk:tree",
@@ -23,7 +23,7 @@
2323
"validateOnSynth": false,
2424
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2525
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b.json",
26+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d.json",
2727
"requiresBootstrapStackVersion": 6,
2828
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2929
"additionalDependencies": [
@@ -237,6 +237,48 @@
237237
"data": "AsgFromMipWithoutDistributionASG4BF292F9"
238238
}
239239
],
240+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice": [
241+
{
242+
"type": "aws:cdk:warning",
243+
"data": "desiredCapacity has been configured. Be aware this will reset the size of your AutoScalingGroup on every deployment. See https://github.com/aws/aws-cdk/issues/5215"
244+
}
245+
],
246+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceSecurityGroup/Resource": [
247+
{
248+
"type": "aws:cdk:logicalId",
249+
"data": "AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206"
250+
}
251+
],
252+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole/Resource": [
253+
{
254+
"type": "aws:cdk:logicalId",
255+
"data": "AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
256+
}
257+
],
258+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceProfile": [
259+
{
260+
"type": "aws:cdk:logicalId",
261+
"data": "AsgWithGp3BlockdeviceInstanceProfile2FC414A5"
262+
}
263+
],
264+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/LaunchConfig": [
265+
{
266+
"type": "aws:cdk:logicalId",
267+
"data": "AsgWithGp3BlockdeviceLaunchConfig24411F5E"
268+
}
269+
],
270+
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/ASG": [
271+
{
272+
"type": "aws:cdk:logicalId",
273+
"data": "AsgWithGp3BlockdeviceASGE82AA487"
274+
}
275+
],
276+
"/aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
277+
{
278+
"type": "aws:cdk:logicalId",
279+
"data": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
280+
}
281+
],
240282
"/aws-cdk-asg-integ/BootstrapVersion": [
241283
{
242284
"type": "aws:cdk:logicalId",

0 commit comments

Comments
 (0)