Skip to content

Commit

Permalink
feat: adds gp3 throughput support to asg
Browse files Browse the repository at this point in the history
resolves: #16213
  • Loading branch information
csumpter committed Oct 10, 2022
1 parent 60176b9 commit 78ef388
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 29 deletions.
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,36 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', {
});
```

### Block Devices

This type specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes.

#### GP3 Volumes

You can only specify the `throughput` on GP3 volumes.

```ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType,
machineImage,
blockDevices: [{
{
deviceName: 'gp3-volume',
volume: autoscaling.BlockDeviceVolume.ebs(15, {
volumeType: autoscaling.EbsDeviceVolumeType.GP3,
throughput: 125,
}),
},
}],
// ...
});
```

## Configuring Instances using CloudFormation Init

It is possible to use the CloudFormation Init mechanism to configure the
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,16 @@ function synthesizeBlockDeviceMappings(construct: Construct, blockDevices: Block
}

if (ebs) {
const { iops, volumeType } = ebs;
const { iops, volumeType, throughput } = ebs;

if (throughput) {
if (volumeType != EbsDeviceVolumeType.GP3) {
throw new Error('throughput property requires volumeType: EbsDeviceVolumeType.GP3');
}
if (throughput < 125 || throughput > 1000) {
throw new Error('throughput property takes a minimum of 125 and a maximum of 1000');
}
}

if (!iops) {
if (volumeType === EbsDeviceVolumeType.IO1) {
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export interface EbsDeviceOptionsBase {
* @default {@link EbsDeviceVolumeType.GP2}
*/
readonly volumeType?: EbsDeviceVolumeType;

/**
* The throughput that the volume supports, in MiB/s
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
* @default - 125 MiB/s
*/
readonly throughput?: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "20.0.0",
"version": "21.0.0",
"files": {
"cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b": {
"92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d": {
"source": {
"path": "aws-cdk-asg-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b.json",
"objectKey": "92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,140 @@
"IgnoreUnmodifiedGroupSizeProperties": true
}
}
},
"AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceSecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1"
}
],
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
}
],
"VpcId": {
"Ref": "VPCB9E5F0B4"
}
}
},
"AsgWithGp3BlockdeviceInstanceRoleF52FB39B": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": {
"Fn::Join": [
"",
[
"ec2.",
{
"Ref": "AWS::URLSuffix"
}
]
]
}
}
}
],
"Version": "2012-10-17"
},
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
}
]
}
},
"AsgWithGp3BlockdeviceInstanceProfile2FC414A5": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Roles": [
{
"Ref": "AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
}
]
}
},
"AsgWithGp3BlockdeviceLaunchConfig24411F5E": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t3.micro",
"BlockDeviceMappings": [
{
"DeviceName": "ebs",
"Ebs": {
"DeleteOnTermination": true,
"Encrypted": true,
"Throughput": 125,
"VolumeSize": 15,
"VolumeType": "gp3"
}
}
],
"IamInstanceProfile": {
"Ref": "AsgWithGp3BlockdeviceInstanceProfile2FC414A5"
},
"SecurityGroups": [
{
"Fn::GetAtt": [
"AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206",
"GroupId"
]
}
],
"UserData": {
"Fn::Base64": "#!/bin/bash"
}
},
"DependsOn": [
"AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
]
},
"AsgWithGp3BlockdeviceASGE82AA487": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"MaxSize": "10",
"MinSize": "0",
"DesiredCapacity": "5",
"LaunchConfigurationName": {
"Ref": "AsgWithGp3BlockdeviceLaunchConfig24411F5E"
},
"Tags": [
{
"Key": "Name",
"PropagateAtLaunch": true,
"Value": "aws-cdk-asg-integ/AsgWithGp3Blockdevice"
}
],
"VPCZoneIdentifier": [
{
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
},
{
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
}
]
},
"UpdatePolicy": {
"AutoScalingScheduledAction": {
"IgnoreUnmodifiedGroupSizeProperties": true
}
}
}
},
"Parameters": {
Expand All @@ -636,6 +770,10 @@
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-arm64-gp2"
},
"SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
},
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"20.0.0"}
{"version":"21.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "21.0.0",
"testCases": {
"integ.asg-lt": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "21.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
Expand All @@ -23,7 +23,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cb1b7cc4cd8286ab836dcbb42f408e2c39d60c34a017d1dac4b998c1891d843b.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/92e76df1c27ca166c25778ea9aba509409d5d5011fce65dbff63251e4422a71d.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -237,6 +237,48 @@
"data": "AsgFromMipWithoutDistributionASG4BF292F9"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice": [
{
"type": "aws:cdk:warning",
"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"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceSecurityGroup/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithGp3BlockdeviceInstanceRoleF52FB39B"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceProfile": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithGp3BlockdeviceInstanceProfile2FC414A5"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/LaunchConfig": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithGp3BlockdeviceLaunchConfig24411F5E"
}
],
"/aws-cdk-asg-integ/AsgWithGp3Blockdevice/ASG": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithGp3BlockdeviceASGE82AA487"
}
],
"/aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
{
"type": "aws:cdk:logicalId",
"data": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
}
],
"/aws-cdk-asg-integ/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
Expand Down
Loading

0 comments on commit 78ef388

Please sign in to comment.