From cc997ab0784199f79e30dcaa60e4fbb997fb65fe Mon Sep 17 00:00:00 2001 From: wafuwafu13 Date: Fri, 22 Dec 2023 20:05:16 +0900 Subject: [PATCH 1/5] feat(autoscaling/LaunchTemplateOverrides): add support for InstanceRequirements --- .../aws-autoscaling/lib/auto-scaling-group.ts | 22 ++++- .../test/auto-scaling-group.test.ts | 89 +++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 1484d7e4df01a..2349c8ca71d03 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -550,13 +550,27 @@ export interface InstancesDistribution { * LaunchTemplateOverrides is a subproperty of LaunchTemplate that describes an override for a launch template. */ export interface LaunchTemplateOverrides { + /** + * The instance requirements. Amazon EC2 Auto Scaling uses your specified requirements to identify instance types. + * Then, it uses your On-Demand and Spot allocation strategies to launch instances from these instance types. + * You can specify up to four separate sets of instance requirements per Auto Scaling group. + * This is useful for provisioning instances from different Amazon Machine Images (AMIs) in the same Auto Scaling group. + * To do this, create the AMIs and create a new launch template for each AMI. + * Then, create a compatible set of instance requirements for each launch template. + * + * If you specify InstanceRequirements, you can't specify InstanceType. + * + * @default - Do not override instance type + */ + readonly instanceRequirements?: CfnAutoScalingGroup.InstanceRequirementsProperty + /** * The instance type, such as m3.xlarge. You must use an instance type that is supported in your requested Region * and Availability Zones. * * @default - Do not override instance type */ - readonly instanceType: ec2.InstanceType, + readonly instanceType?: ec2.InstanceType, /** * Provides the launch template to be used when launching the instance type. For example, some instance types might @@ -1810,11 +1824,15 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements if (override.weightedCapacity && Math.floor(override.weightedCapacity) !== override.weightedCapacity) { throw new Error('Weight must be an integer'); } + if (override.instanceType && override.instanceRequirements) { + throw new Error('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); + } return { - instanceType: override.instanceType.toString(), + instanceType: override.instanceType?.toString(), launchTemplateSpecification: override.launchTemplate ? this.convertILaunchTemplateToSpecification(override.launchTemplate) : undefined, + instanceRequirements: override.instanceRequirements, weightedCapacity: override.weightedCapacity?.toString(), }; }), diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index d61e439df1965..af691e92c92dc 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -1862,6 +1862,95 @@ describe('auto scaling group', () => { }); }); + test('Can specify InstanceRequirements', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', { + launchTemplateId: 'test-lt-id', + versionNumber: '0', + }); + + new autoscaling.AutoScalingGroup(stack, 'mip-asg', { + mixedInstancesPolicy: { + launchTemplate: lt, + launchTemplateOverrides: [{ + instanceRequirements: { + vCpuCount: { min: 4, max: 8 }, + memoryMiB: { min: 16384 }, + cpuManufacturers: ['intel'], + }, + launchTemplate: lt, + weightedCapacity: 9, + }], + }, + vpc: mockVpc(stack), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + MixedInstancesPolicy: { + LaunchTemplate: { + LaunchTemplateSpecification: { + LaunchTemplateId: 'test-lt-id', + Version: '0', + }, + Overrides: [ + { + InstanceRequirements: { + VCpuCount: { + Min: 4, + Max: 8, + }, + MemoryMiB: { + Min: 16384, + }, + CpuManufacturers: ['intel'], + }, + LaunchTemplateSpecification: { + LaunchTemplateId: 'test-lt-id', + Version: '0', + }, + WeightedCapacity: '9', + }, + ], + }, + }, + }); + }); + + test('Cannot specify InstanceRequirements and InstanceType at the same time', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', { + launchTemplateId: 'test-lt-id', + versionNumber: '0', + }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'mip-asg', { + mixedInstancesPolicy: { + launchTemplate: lt, + launchTemplateOverrides: [{ + instanceRequirements: { + vCpuCount: { min: 4, max: 8 }, + memoryMiB: { min: 16384 }, + cpuManufacturers: ['intel'], + }, + instanceType: new InstanceType('t4g.micro'), + launchTemplate: lt, + weightedCapacity: 9, + }], + }, + vpc: mockVpc(stack), + }); + }).toThrow('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); + }); + test('Cannot specify both Launch Template and Launch Config', () => { // GIVEN const stack = new cdk.Stack(); From 36439766ccb2e836fb6e2ab79fdefe4058fbd88b Mon Sep 17 00:00:00 2001 From: wafuwafu13 Date: Sat, 23 Dec 2023 12:48:49 +0900 Subject: [PATCH 2/5] test(autoscaling): add integration test --- .../aws-cdk-asg-integ.assets.json | 6 +- .../aws-cdk-asg-integ.template.json | 52 +++ .../test/integ.asg-lt.js.snapshot/cdk.out | 2 +- .../test/integ.asg-lt.js.snapshot/integ.json | 2 +- .../integ.asg-lt.js.snapshot/manifest.json | 16 +- .../test/integ.asg-lt.js.snapshot/tree.json | 395 ++++++++++-------- .../test/aws-autoscaling/test/integ.asg-lt.ts | 19 + 7 files changed, 320 insertions(+), 172 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.assets.json index 75b327e1f1d67..ac046e7bb6776 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.assets.json @@ -1,7 +1,7 @@ { - "version": "34.0.0", + "version": "35.0.0", "files": { - "7a8efad29e5cb8979aac968ca3709d9f3c874be848a2097779d79b8be52e4fd9": { + "cc56cf10db6f9a8d08a1dd3ac11545a658835fe20afe0105866946e153d2d173": { "source": { "path": "aws-cdk-asg-integ.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "7a8efad29e5cb8979aac968ca3709d9f3c874be848a2097779d79b8be52e4fd9.json", + "objectKey": "cc56cf10db6f9a8d08a1dd3ac11545a658835fe20afe0105866946e153d2d173.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.template.json index c717d216f0346..03aa1485838e2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.template.json @@ -716,6 +716,58 @@ } } }, + "AsgFromMipWithInstanceRequirementsASG8BFE597D": { + "Type": "AWS::AutoScaling::AutoScalingGroup", + "Properties": { + "DesiredCapacity": "5", + "MaxSize": "10", + "MinSize": "0", + "MixedInstancesPolicy": { + "LaunchTemplate": { + "LaunchTemplateSpecification": { + "LaunchTemplateId": { + "Ref": "MainLT4FC09097" + }, + "Version": { + "Fn::GetAtt": [ + "MainLT4FC09097", + "LatestVersionNumber" + ] + } + }, + "Overrides": [ + { + "InstanceRequirements": { + "CpuManufacturers": [ + "intel" + ], + "MemoryMiB": { + "Min": 16384 + }, + "VCpuCount": { + "Max": 8, + "Min": 4 + } + } + } + ] + } + }, + "VPCZoneIdentifier": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ] + }, + "UpdatePolicy": { + "AutoScalingScheduledAction": { + "IgnoreUnmodifiedGroupSizeProperties": true + } + } + }, "AsgWithGp3BlockdeviceInstanceSecurityGroup54D76206": { "Type": "AWS::EC2::SecurityGroup", "Properties": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/cdk.out index 2313ab5436501..c5cb2e5de6344 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"34.0.0"} \ No newline at end of file +{"version":"35.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/integ.json index c14907a26af33..00d876c307c28 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "34.0.0", + "version": "35.0.0", "testCases": { "integ.asg-lt": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/manifest.json index 64d7772a46cc1..61de7b207eb34 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "34.0.0", + "version": "35.0.0", "artifacts": { "aws-cdk-asg-integ.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,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}/7a8efad29e5cb8979aac968ca3709d9f3c874be848a2097779d79b8be52e4fd9.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cc56cf10db6f9a8d08a1dd3ac11545a658835fe20afe0105866946e153d2d173.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -250,6 +250,18 @@ "data": "AsgFromMipWithoutDistributionASG4BF292F9" } ], + "/aws-cdk-asg-integ/AsgFromMipWithInstanceRequirements": [ + { + "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 [ack: @aws-cdk/aws-autoscaling:desiredCapacitySet]" + } + ], + "/aws-cdk-asg-integ/AsgFromMipWithInstanceRequirements/ASG": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgFromMipWithInstanceRequirementsASG8BFE597D" + } + ], "/aws-cdk-asg-integ/AsgWithGp3Blockdevice": [ { "type": "aws:cdk:warning", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/tree.json index 3c4a2f70265cc..2e7c5f9aecfb6 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/tree.json @@ -16,8 +16,8 @@ "id": "Importrole", "path": "aws-cdk-asg-integ/role/Importrole", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "Resource": { @@ -55,14 +55,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" } }, "MainLT": { @@ -83,8 +83,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" } }, "Resource": { @@ -144,30 +144,30 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "T4gLT": { @@ -223,30 +223,30 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-arm64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "VPC": { @@ -272,8 +272,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", + "version": "0.0.0" } }, "PublicSubnet1": { @@ -316,16 +316,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-asg-integ/VPC/PublicSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -346,8 +346,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" } }, "RouteTableAssociation": { @@ -365,8 +365,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" } }, "DefaultRoute": { @@ -385,8 +385,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" } }, "EIP": { @@ -405,8 +405,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" } }, "NATGateway": { @@ -433,14 +433,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" } }, "PublicSubnet2": { @@ -483,16 +483,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-asg-integ/VPC/PublicSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -513,8 +513,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" } }, "RouteTableAssociation": { @@ -532,8 +532,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" } }, "DefaultRoute": { @@ -552,8 +552,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" } }, "EIP": { @@ -572,8 +572,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" } }, "NATGateway": { @@ -600,14 +600,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" } }, "PrivateSubnet1": { @@ -650,16 +650,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-asg-integ/VPC/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -680,8 +680,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" } }, "RouteTableAssociation": { @@ -699,8 +699,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" } }, "DefaultRoute": { @@ -719,14 +719,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" } }, "PrivateSubnet2": { @@ -769,16 +769,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-asg-integ/VPC/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -799,8 +799,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" } }, "RouteTableAssociation": { @@ -818,8 +818,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" } }, "DefaultRoute": { @@ -838,14 +838,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" } }, "IGW": { @@ -863,8 +863,8 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", + "version": "0.0.0" } }, "VPCGW": { @@ -882,14 +882,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.Vpc", + "version": "0.0.0" } }, "AsgFromLT": { @@ -927,14 +927,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "AsgWithDefaultInstanceWarmup": { @@ -972,14 +972,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "AsgFromMip": { @@ -1046,14 +1046,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "AsgFromMipWithoutDistribution": { @@ -1117,14 +1117,79 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" + } + }, + "AsgFromMipWithInstanceRequirements": { + "id": "AsgFromMipWithInstanceRequirements", + "path": "aws-cdk-asg-integ/AsgFromMipWithInstanceRequirements", + "children": { + "ASG": { + "id": "ASG", + "path": "aws-cdk-asg-integ/AsgFromMipWithInstanceRequirements/ASG", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup", + "aws:cdk:cloudformation:props": { + "desiredCapacity": "5", + "maxSize": "10", + "minSize": "0", + "mixedInstancesPolicy": { + "launchTemplate": { + "launchTemplateSpecification": { + "launchTemplateId": { + "Ref": "MainLT4FC09097" + }, + "version": { + "Fn::GetAtt": [ + "MainLT4FC09097", + "LatestVersionNumber" + ] + } + }, + "overrides": [ + { + "instanceRequirements": { + "vCpuCount": { + "min": 4, + "max": 8 + }, + "memoryMiB": { + "min": 16384 + }, + "cpuManufacturers": [ + "intel" + ] + } + } + ] + } + }, + "vpcZoneIdentifier": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "AsgWithGp3Blockdevice": { @@ -1161,14 +1226,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" } }, "InstanceRole": { @@ -1179,8 +1244,8 @@ "id": "ImportInstanceRole", "path": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole/ImportInstanceRole", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "Resource": { @@ -1210,14 +1275,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" } }, "InstanceProfile": { @@ -1234,16 +1299,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" } }, "ImportedInstanceProfile": { "id": "ImportedInstanceProfile", "path": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/ImportedInstanceProfile", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "LaunchTemplate": { @@ -1330,14 +1395,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", + "version": "0.0.0" } }, "ASG": { @@ -1378,30 +1443,30 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "AsgWithIMDSv2": { @@ -1438,14 +1503,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" } }, "InstanceRole": { @@ -1456,8 +1521,8 @@ "id": "ImportInstanceRole", "path": "aws-cdk-asg-integ/AsgWithIMDSv2/InstanceRole/ImportInstanceRole", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "Resource": { @@ -1487,14 +1552,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" } }, "InstanceProfile": { @@ -1511,16 +1576,16 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" } }, "ImportedInstanceProfile": { "id": "ImportedInstanceProfile", "path": "aws-cdk-asg-integ/AsgWithIMDSv2/ImportedInstanceProfile", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "LaunchTemplate": { @@ -1598,14 +1663,14 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", + "version": "0.0.0" } }, "ASG": { @@ -1645,52 +1710,52 @@ } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "aws-cdk-asg-integ/BootstrapVersion", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "aws-cdk-asg-integ/CheckBootstrapVersion", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" } }, "Tree": { @@ -1698,13 +1763,13 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.70" + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.2.70" + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.ts index 6582f6c2b5b71..86130397b2dd3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.ts @@ -84,6 +84,25 @@ new autoscaling.AutoScalingGroup(stack, 'AsgFromMipWithoutDistribution', { desiredCapacity: 5, }); +new autoscaling.AutoScalingGroup(stack, 'AsgFromMipWithInstanceRequirements', { + vpc, + mixedInstancesPolicy: { + launchTemplate: lt, + launchTemplateOverrides: [ + { + instanceRequirements: { + vCpuCount: { min: 4, max: 8 }, + memoryMiB: { min: 16384 }, + cpuManufacturers: ['intel'], + }, + }, + ], + }, + minCapacity: 0, + maxCapacity: 10, + desiredCapacity: 5, +}); + new autoscaling.AutoScalingGroup(stack, 'AsgWithGp3Blockdevice', { minCapacity: 0, maxCapacity: 10, From cf2451674d729c4187f97afbde381416b3b228c3 Mon Sep 17 00:00:00 2001 From: wafuwafu13 Date: Sat, 23 Dec 2023 12:49:26 +0900 Subject: [PATCH 3/5] docs(autoscaling): add doc for InstanceRequirements --- .../aws-cdk-lib/aws-autoscaling/README.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 4fbbafe1a6bc6..b033f0257e3fb 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -91,6 +91,29 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` +You can specify instance requirements in `InstanceRequirements`: + +```ts +declare const vpc: ec2.Vpc; +declare const launchTemplate1: ec2.LaunchTemplate; + +new autoscaling.AutoScalingGroup(this, 'ASG', { + vpc, + mixedInstancesPolicy: { + launchTemplate: launchTemplate1, + launchTemplateOverrides: [ + { + instanceRequirements: { + vCpuCount: { min: 4, max: 8 }, + memoryMiB: { min: 16384 }, + cpuManufacturers: ['intel'], + }, + } + ], + } +}); +``` + ## Machine Images (AMIs) AMIs control the OS that gets launched when you start your EC2 instance. The EC2 From f9d3a8ee8e9cfff8ae0af79b7f980d5ab61d5420 Mon Sep 17 00:00:00 2001 From: wafuwafu13 Date: Sun, 24 Dec 2023 03:00:38 +0000 Subject: [PATCH 4/5] fix(autoscaling): should specify either InstanceRequirements or InstanceType --- .../aws-autoscaling/lib/auto-scaling-group.ts | 3 +++ .../test/auto-scaling-group.test.ts | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 2349c8ca71d03..b4f07cf85158a 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1824,6 +1824,9 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements if (override.weightedCapacity && Math.floor(override.weightedCapacity) !== override.weightedCapacity) { throw new Error('Weight must be an integer'); } + if (!override.instanceType && !override.instanceRequirements) { + throw new Error('You must specify either \'instanceRequirements\' or \'instanceType\'.'); + } if (override.instanceType && override.instanceRequirements) { throw new Error('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); } diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index af691e92c92dc..5bb326f6e60fe 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -1951,6 +1951,31 @@ describe('auto scaling group', () => { }).toThrow('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); }); + test('Should specify either InstanceRequirements or InstanceType', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', { + launchTemplateId: 'test-lt-id', + versionNumber: '0', + }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'mip-asg', { + mixedInstancesPolicy: { + launchTemplate: lt, + launchTemplateOverrides: [{ + launchTemplate: lt, + weightedCapacity: 9, + }], + }, + vpc: mockVpc(stack), + }); + }).toThrow('You must specify either \'instanceRequirements\' or \'instanceType\'.'); + }); + test('Cannot specify both Launch Template and Launch Config', () => { // GIVEN const stack = new cdk.Stack(); From 2fb32afc85eed7b7b4649f7bbafae50974f6e27d Mon Sep 17 00:00:00 2001 From: wafuwafu13 Date: Sun, 24 Dec 2023 03:09:40 +0000 Subject: [PATCH 5/5] docs(autoscaling): make it more readable --- packages/aws-cdk-lib/aws-autoscaling/README.md | 2 +- .../aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 7 +++++-- .../aws-autoscaling/test/auto-scaling-group.test.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index b033f0257e3fb..59ad851099532 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -91,7 +91,7 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` -You can specify instance requirements in `InstanceRequirements`: +You can specify instances requirements with the `instanceRequirements ` property: ```ts declare const vpc: ec2.Vpc; diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index b4f07cf85158a..578a2fd6cd9ed 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -553,12 +553,13 @@ export interface LaunchTemplateOverrides { /** * The instance requirements. Amazon EC2 Auto Scaling uses your specified requirements to identify instance types. * Then, it uses your On-Demand and Spot allocation strategies to launch instances from these instance types. + * * You can specify up to four separate sets of instance requirements per Auto Scaling group. * This is useful for provisioning instances from different Amazon Machine Images (AMIs) in the same Auto Scaling group. * To do this, create the AMIs and create a new launch template for each AMI. * Then, create a compatible set of instance requirements for each launch template. * - * If you specify InstanceRequirements, you can't specify InstanceType. + * You must specify one of instanceRequirements or instanceType. * * @default - Do not override instance type */ @@ -568,6 +569,8 @@ export interface LaunchTemplateOverrides { * The instance type, such as m3.xlarge. You must use an instance type that is supported in your requested Region * and Availability Zones. * + * You must specify one of instanceRequirements or instanceType. + * * @default - Do not override instance type */ readonly instanceType?: ec2.InstanceType, @@ -1828,7 +1831,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements throw new Error('You must specify either \'instanceRequirements\' or \'instanceType\'.'); } if (override.instanceType && override.instanceRequirements) { - throw new Error('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); + throw new Error('You can specify either \'instanceRequirements\' or \'instanceType\', not both.'); } return { instanceType: override.instanceType?.toString(), diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 5bb326f6e60fe..ba8791f4c77d5 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -1948,7 +1948,7 @@ describe('auto scaling group', () => { }, vpc: mockVpc(stack), }); - }).toThrow('\'InstanceRequirements\' can\'t be specified with \'InstanceType\''); + }).toThrow('You can specify either \'instanceRequirements\' or \'instanceType\', not both.'); }); test('Should specify either InstanceRequirements or InstanceType', () => {