From 688a64350bcd658cf29345f4aaeda9a7be629b9d Mon Sep 17 00:00:00 2001 From: Ashwini Kumar Date: Mon, 13 Jun 2022 19:27:29 +0530 Subject: [PATCH 1/4] Added ABIS feature to Auto Scaling workshop --- .../create_asg.md | 103 ++++++++++++++++-- .../asg-old-list.json | 71 ++++++++++++ .../asg.json | 52 ++++++--- 3 files changed, 201 insertions(+), 25 deletions(-) create mode 100644 workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json diff --git a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md index 0cab50f8..407b16bd 100644 --- a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md +++ b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md @@ -7,16 +7,23 @@ To launch, maintain and scale EC2 instances dynamically for your application, yo Amazon EC2 Auto Scaling helps you maintain application availability and allows you to dynamically scale your Amazon EC2 capacity up or down automatically according to conditions you define. You can use Amazon EC2 Auto Scaling for fleet management of EC2 instances to help maintain the health and availability of your fleet and ensure that you are running your desired number of Amazon EC2 instances. You can also use Amazon EC2 Auto Scaling for dynamic scaling of EC2 instances in order to automatically increase the number of Amazon EC2 instances during demand spikes to maintain performance and decrease capacity during lulls to reduce costs. Amazon EC2 Auto Scaling is well suited both to applications that have stable demand patterns or that experience hourly, daily, or weekly variability in usage. You can find more information on the [Auto Scaling documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html). -1. Open **asg.json** on the Cloud9 editor and review the configuration. Pay special attention at the **Overrides** and the **InstancesDistribution**. Take a look at our [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-allocation-strategies) to review how InstancesDistribution and allocation strategies work. You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). -{{%expand "Help me understand the AutoScaling configuration" %}} -The **Overrides** configuration block provides EC2 AutoScaling the list of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and multiple availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. You can use the [EC2 Instance Types console](https://console.aws.amazon.com/ec2/v2/home?#InstanceTypes:) or the [ec2-instance-selector](https://github.com/aws/amazon-ec2-instance-selector) CLI tool to find suitable instance types. To adhere to best practices and maximize your chances of launching your target Spot capacity, configure a minimum of 6 different instance types across 3 Availability Zones). That would give you the ability to provision Spot capacity from 18 different capacity pools. +1. Open **asg.json** on the Cloud9 editor and review the configuration. Pay special attention at the **Overrides** and the **InstancesDistribution**. Take a look at our [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-allocation-strategies) to review how InstancesDistribution and allocation strategies work. You will see in the Overrides block that instead of choosing and specifying instance types, we are specifying [instance requirements](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstanceRequirements.html) as a set of instance attributes. You will use a feature called **Attribute based Instance Type Selection** that lets you express your instance requirements, as a set of attributes including vCPUs, memory, memory per vCPU, processor architecture, instance generation, GPU count and more. Your requirements are automatically translated to all matching instance types whenever EC2 Auto Scaling launches instances. This also allows Auto Scaling groups to automatically use newer generation instance types, as and when they are released. This feature eliminates the undifferentiated heavy lifting of manually selecting, specifying and maintaining instance types list in the Overrides configuration block. To learn more about Attribute based Instance Type Selection, please take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) and this [blog](https://aws.amazon.com/blogs/aws/new-attribute-based-instance-type-selection-for-ec2-auto-scaling-and-ec2-fleet/). You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). -Then, the *InstancesDistribution* configuration block determines how EC2 Auto Scaling picks the instance types to use, while at the same time it keeps a balanced number of EC2 instances per Availability Zone. +{{%expand "Help me understand Auto Scaling group configuration with Attribute based Instance Type Selection" %}} +The **Overrides** configuration block provides EC2 Auto Scaling a choice of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and multiple availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. We are using **Attribute based Instance Type Selection** feature to specify instance attributes, instead of manually selecting and specifying instance types. For the purpose of this workshop, let's assume that your workload is flexible to run on any of the instance types matching below attributes: + * Instances with 2 vCPUs + * Instances with minimum 4 GiB and maximum 16 GiB memory + * Instances which have minimum vCPU to Memory ratio 1:2 and maximum vCPU to Memory ratio of 1:8 + * Instances with CPU Architecture of Intel and AMD and no GPU Instances + * Instances that belong to current generation + * Excluding Instance families of type: d*,h*,i*,x* and z* -* The **prioritized** allocation strategy for on-demand instances makes AutoScaling try to launch the first instance type of your list and skip to the next instance type if for any reason it's unable to launch it (e.g. temporary unavailability of capacity). This is particularly useful if you have [Reserved Instances](https://aws.amazon.com/ec2/pricing/reserved-instances/) or [Savings Plans](https://aws.amazon.com/savingsplans/) for your baseline capacity, so Auto Scaling launches the instance type matching your reservations. +You can see that above criteria is configured in the *InstanceRequirements* block of the *Overrides* configuration in *asg.json*. Then, the *InstancesDistribution* configuration block determines how EC2 Auto Scaling picks the instance types to use, while at the same time it keeps a balanced number of EC2 instances per Availability Zone. + +* **OnDemandAllocationStrategy** is **lowest-price**, which makes Auto Scaling try to launch on-demand instances from the lowest priced instance pools. You must use *lowest-price* as your on-demand allocation strategy with *Attribute based Instance Type Selection* feature. To use the **prioritized** allocation strategy, you must continue to manually add and prioritize your instance types in the Overrides list. This may be required if you have [Reserved Instances](https://aws.amazon.com/ec2/pricing/reserved-instances/) or [Savings Plans](https://aws.amazon.com/savingsplans/) for your baseline capacity, so that Auto Scaling launches the instance type matching your reservations. * **OnDemandBaseCapacity** is set to 2, meaning the first two EC2 instances launched by EC2 AutoScaling will be on-demand. * **OnDemandPercentageAboveBaseCapacity** is set to 0 so all the additional instances will be launched as Spot Instances -* **SpotAllocationStrategy** is capacity-optimized, which instructs AutoScaling to pick the optimal instance type on each Availability Zone based on launch time availability of spare capacity for your instance type selection. +* **SpotAllocationStrategy** is **capacity-optimized**, which instructs Auto Scaling to pick the optimal instance type on each Availability Zone based on launch time availability of spare capacity for your instance type selection. With *Attribute based Instance Type Selection*, your Spot allocation strategy must be either *capacity-optimized* or *lowest-price* and to use the *capacity-optimized-prioritized* allocation strategy, you must manually add and prioritize your instance types. {{% /expand %}} 2. You will notice there are placeholder values for **`%TargetGroupArn%`**, **`%publicSubnet1%`** and **`%publicSubnet2%`**. To update the configuration file with the values of the Target Group you created previously and the outputs from the CloudFormation template, execute the following command: @@ -37,4 +44,86 @@ This command will not return any output if it is successful. # Optional exercise -Now that you have deployed an EC2 Auto Scaling group with Mixed Instance Types and Purchase options, take some time to go through the different configurations in the [console](https://console.aws.amazon.com/ec2autoscaling/home?#/). Click on the **myEC2Workshop** Auto Scaling group and go to the *Purchase options and instance types* section and try to edit the instance types configured on the Auto Scaling group and change the "primary instance type" to see how the Auto Scaling console provides you a recommended list of instance types based on your selected instance type. \ No newline at end of file +Now that you have deployed an EC2 Auto Scaling group with Mixed Instance Types and Purchase options, take some time to go through the different configurations in the [console](https://console.aws.amazon.com/ec2autoscaling/home?#/). Click on the **myEC2Workshop** Auto Scaling group and go to the *Instance type requirements* section and click *Edit* button and scroll down to *Preview matching instance types*. Expand to see list of instance types based on your selected instance attributes. Try to edit the instance requirements configured on the Auto Scaling group and see how this preview list changes. + + +{{%expand "Optional-Auto Scaling group configuration with manual instance types list" %}} +**Optionally**, you can use the [EC2 Instance Types console](https://console.aws.amazon.com/ec2/v2/home?#InstanceTypes:) or the [ec2-instance-selector](https://github.com/aws/amazon-ec2-instance-selector) CLI tool to find suitable instance types. To adhere to best practices, minimize Spot interruptions and maximize your chances of launching your target Spot capacity, configure as many different instance types as possible. EC2 Auto Scaling allows you to specify up to 40 different instance types. For the purpose of this workshop, we will use a minimum of 12 different instance types across 3 Availability Zones. That would give you the ability to provision Spot capacity from 36 different capacity pools. + +If you have [Reserved Instances](https://aws.amazon.com/ec2/pricing/reserved-instances/) or [Savings Plans](https://aws.amazon.com/savingsplans/) for your baseline capacity, you can use the **prioritized** allocation strategy for on-demand instances to make AutoScaling try to launch the first instance type of your list. It will skip to the next instance type if for any reason it's unable to launch first one (e.g. temporary unavailability of capacity). + +Please update your *asg.json* configuration file as below, to manually specify instance types and use *prioritized* On-demand allocation strategy: +``` +{ + "AutoScalingGroupName": "myEC2Workshop", + "MixedInstancesPolicy": { + "LaunchTemplate": { + "LaunchTemplateSpecification": { + "LaunchTemplateName": "myEC2Workshop", + "Version": "1" + }, + "Overrides": [ + { + "InstanceType": "m5.large" + }, + { + "InstanceType": "c5.large" + }, + { + "InstanceType": "m4.large" + }, + { + "InstanceType": "c4.large" + }, + { + "InstanceType": "r5.large" + }, + { + "InstanceType": "r4.large" + }, + { + "InstanceType": "m5a.large" + }, + { + "InstanceType": "c5a.large" + }, + { + "InstanceType": "r5a.large" + }, + { + "InstanceType": "m5d.large" + }, + { + "InstanceType": "c5d.large" + }, + { + "InstanceType": "r5d.large" + } + ] + }, + "InstancesDistribution": { + "OnDemandAllocationStrategy": "prioritized", + "OnDemandBaseCapacity": 2, + "OnDemandPercentageAboveBaseCapacity": 0, + "SpotAllocationStrategy": "capacity-optimized" + } + }, + "MinSize": 2, + "MaxSize": 12, + "DesiredCapacity": 4, + "CapacityRebalance": true, + "TargetGroupARNs": [ + "%TargetGroupARN%" + ], + "HealthCheckType": "EC2", + "VPCZoneIdentifier": "%publicSubnet1%,%publicSubnet2%", + "Tags": [ + { + "Key": "SpotInterruptionHandler/enabled", + "Value": "true", + "PropagateAtLaunch": true + } + ] +} +``` +{{% /expand %}} \ No newline at end of file diff --git a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json new file mode 100644 index 00000000..31c0ed60 --- /dev/null +++ b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json @@ -0,0 +1,71 @@ +{ + "AutoScalingGroupName": "myEC2Workshop", + "MixedInstancesPolicy": { + "LaunchTemplate": { + "LaunchTemplateSpecification": { + "LaunchTemplateName": "myEC2Workshop", + "Version": "1" + }, + "Overrides": [ + { + "InstanceType": "m5.large" + }, + { + "InstanceType": "c5.large" + }, + { + "InstanceType": "m4.large" + }, + { + "InstanceType": "c4.large" + }, + { + "InstanceType": "r5.large" + }, + { + "InstanceType": "r4.large" + }, + { + "InstanceType": "m5a.large" + }, + { + "InstanceType": "c5a.large" + }, + { + "InstanceType": "r5a.large" + }, + { + "InstanceType": "m5d.large" + }, + { + "InstanceType": "c5d.large" + }, + { + "InstanceType": "r5d.large" + } + ] + }, + "InstancesDistribution": { + "OnDemandAllocationStrategy": "prioritized", + "OnDemandBaseCapacity": 2, + "OnDemandPercentageAboveBaseCapacity": 0, + "SpotAllocationStrategy": "capacity-optimized" + } + }, + "MinSize": 2, + "MaxSize": 12, + "DesiredCapacity": 4, + "CapacityRebalance": true, + "TargetGroupARNs": [ + "%TargetGroupARN%" + ], + "HealthCheckType": "EC2", + "VPCZoneIdentifier": "%publicSubnet1%,%publicSubnet2%", + "Tags": [ + { + "Key": "SpotInterruptionHandler/enabled", + "Value": "true", + "PropagateAtLaunch": true + } + ] +} \ No newline at end of file diff --git a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json index ccfefd44..25368edd 100644 --- a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json +++ b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json @@ -8,27 +8,43 @@ }, "Overrides": [ { - "InstanceType": "m5.large" - }, - { - "InstanceType": "c5.large" - }, - { - "InstanceType": "m4.large" - }, - { - "InstanceType": "c4.large" - }, - { - "InstanceType": "r5.large" - }, - { - "InstanceType": "r4.large" + "InstanceRequirements": { + "VCpuCount": { + "Min": 2, + "Max": 2 + }, + "MemoryMiB": { + "Min": 4096, + "Max": 16384 + }, + "MemoryGiBPerVCpu": { + "Min": 2, + "Max": 8 + }, + "CpuManufacturers": [ + "intel", + "amd" + ], + "InstanceGenerations": [ + "current" + ], + "AcceleratorCount": { + "Min": 0, + "Max": 0 + }, + "ExcludedInstanceTypes": [ + "d*", + "h*", + "x*", + "i*", + "z*" + ] + } } ] }, "InstancesDistribution": { - "OnDemandAllocationStrategy": "prioritized", + "OnDemandAllocationStrategy": "lowest-price", "OnDemandBaseCapacity": 2, "OnDemandPercentageAboveBaseCapacity": 0, "SpotAllocationStrategy": "capacity-optimized" @@ -50,4 +66,4 @@ "PropagateAtLaunch": true } ] -} +} \ No newline at end of file From 6d64f26f368bf034260acf4561b7fb8e1a5c076f Mon Sep 17 00:00:00 2001 From: Ashwini Kumar Date: Mon, 13 Jun 2022 19:38:27 +0530 Subject: [PATCH 2/4] Added Attribute based Instance Type selection config --- .../asg-old-list.json | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json diff --git a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json deleted file mode 100644 index 31c0ed60..00000000 --- a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg-old-list.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "AutoScalingGroupName": "myEC2Workshop", - "MixedInstancesPolicy": { - "LaunchTemplate": { - "LaunchTemplateSpecification": { - "LaunchTemplateName": "myEC2Workshop", - "Version": "1" - }, - "Overrides": [ - { - "InstanceType": "m5.large" - }, - { - "InstanceType": "c5.large" - }, - { - "InstanceType": "m4.large" - }, - { - "InstanceType": "c4.large" - }, - { - "InstanceType": "r5.large" - }, - { - "InstanceType": "r4.large" - }, - { - "InstanceType": "m5a.large" - }, - { - "InstanceType": "c5a.large" - }, - { - "InstanceType": "r5a.large" - }, - { - "InstanceType": "m5d.large" - }, - { - "InstanceType": "c5d.large" - }, - { - "InstanceType": "r5d.large" - } - ] - }, - "InstancesDistribution": { - "OnDemandAllocationStrategy": "prioritized", - "OnDemandBaseCapacity": 2, - "OnDemandPercentageAboveBaseCapacity": 0, - "SpotAllocationStrategy": "capacity-optimized" - } - }, - "MinSize": 2, - "MaxSize": 12, - "DesiredCapacity": 4, - "CapacityRebalance": true, - "TargetGroupARNs": [ - "%TargetGroupARN%" - ], - "HealthCheckType": "EC2", - "VPCZoneIdentifier": "%publicSubnet1%,%publicSubnet2%", - "Tags": [ - { - "Key": "SpotInterruptionHandler/enabled", - "Value": "true", - "PropagateAtLaunch": true - } - ] -} \ No newline at end of file From 6fdc5ed15a6cf492af394db1568e84deb9771ae4 Mon Sep 17 00:00:00 2001 From: Ashwini Kumar Date: Fri, 26 Aug 2022 13:48:36 +0530 Subject: [PATCH 3/4] changes in abs part --- .../create_asg.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md index 407b16bd..25ec3c3d 100644 --- a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md +++ b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md @@ -7,10 +7,14 @@ To launch, maintain and scale EC2 instances dynamically for your application, yo Amazon EC2 Auto Scaling helps you maintain application availability and allows you to dynamically scale your Amazon EC2 capacity up or down automatically according to conditions you define. You can use Amazon EC2 Auto Scaling for fleet management of EC2 instances to help maintain the health and availability of your fleet and ensure that you are running your desired number of Amazon EC2 instances. You can also use Amazon EC2 Auto Scaling for dynamic scaling of EC2 instances in order to automatically increase the number of Amazon EC2 instances during demand spikes to maintain performance and decrease capacity during lulls to reduce costs. Amazon EC2 Auto Scaling is well suited both to applications that have stable demand patterns or that experience hourly, daily, or weekly variability in usage. You can find more information on the [Auto Scaling documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html). -1. Open **asg.json** on the Cloud9 editor and review the configuration. Pay special attention at the **Overrides** and the **InstancesDistribution**. Take a look at our [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-allocation-strategies) to review how InstancesDistribution and allocation strategies work. You will see in the Overrides block that instead of choosing and specifying instance types, we are specifying [instance requirements](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstanceRequirements.html) as a set of instance attributes. You will use a feature called **Attribute based Instance Type Selection** that lets you express your instance requirements, as a set of attributes including vCPUs, memory, memory per vCPU, processor architecture, instance generation, GPU count and more. Your requirements are automatically translated to all matching instance types whenever EC2 Auto Scaling launches instances. This also allows Auto Scaling groups to automatically use newer generation instance types, as and when they are released. This feature eliminates the undifferentiated heavy lifting of manually selecting, specifying and maintaining instance types list in the Overrides configuration block. To learn more about Attribute based Instance Type Selection, please take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) and this [blog](https://aws.amazon.com/blogs/aws/new-attribute-based-instance-type-selection-for-ec2-auto-scaling-and-ec2-fleet/). You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). +1. Open **asg.json** on the Cloud9 editor and review the configuration. Pay special attention at the **Overrides** and the **InstancesDistribution**. Take a look at our [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-allocation-strategies) to review how InstancesDistribution and allocation strategies work. + +2. The **Overrides** configuration block provides EC2 Auto Scaling a choice of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. You will see in the Overrides block that instead of choosing and specifying instance types, we are specifying [instance requirements](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstanceRequirements.html) as a set of instance attributes. + +2. You will use a feature called **Attribute based Instance Type Selection** that lets you express your instance requirements, as a set of attributes including vCPUs, memory, memory per vCPU, processor architecture, instance generation, GPU count and more. Your requirements are automatically translated to all matching instance types whenever EC2 Auto Scaling launches instances. This also allows Auto Scaling groups to automatically use newer generation instance types, as and when they are released. This feature eliminates the undifferentiated heavy lifting of manually selecting, specifying and maintaining instance types list in the Overrides configuration block. To learn more about Attribute based Instance Type Selection, please take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) and this [blog](https://aws.amazon.com/blogs/aws/new-attribute-based-instance-type-selection-for-ec2-auto-scaling-and-ec2-fleet/). You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). {{%expand "Help me understand Auto Scaling group configuration with Attribute based Instance Type Selection" %}} -The **Overrides** configuration block provides EC2 Auto Scaling a choice of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and multiple availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. We are using **Attribute based Instance Type Selection** feature to specify instance attributes, instead of manually selecting and specifying instance types. For the purpose of this workshop, let's assume that your workload is flexible to run on any of the instance types matching below attributes: +We are using **Attribute based Instance Type Selection** feature to specify instance attributes, instead of manually selecting and specifying instance types. For the purpose of this workshop, let's assume that your workload is flexible to run on any of the instance types matching below attributes: * Instances with 2 vCPUs * Instances with minimum 4 GiB and maximum 16 GiB memory * Instances which have minimum vCPU to Memory ratio 1:2 and maximum vCPU to Memory ratio of 1:8 From 58b2144619a6fc1287069ed33390c3cdae51bf84 Mon Sep 17 00:00:00 2001 From: Ashwini Kumar Date: Fri, 26 Aug 2022 14:48:36 +0530 Subject: [PATCH 4/4] incorporated review comments --- .../create_asg.md | 146 ++++++------------ .../asg.json | 7 - 2 files changed, 50 insertions(+), 103 deletions(-) diff --git a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md index 25ec3c3d..bf808892 100644 --- a/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md +++ b/content/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/create_asg.md @@ -9,33 +9,69 @@ Amazon EC2 Auto Scaling helps you maintain application availability and allows y 1. Open **asg.json** on the Cloud9 editor and review the configuration. Pay special attention at the **Overrides** and the **InstancesDistribution**. Take a look at our [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-allocation-strategies) to review how InstancesDistribution and allocation strategies work. -2. The **Overrides** configuration block provides EC2 Auto Scaling a choice of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. You will see in the Overrides block that instead of choosing and specifying instance types, we are specifying [instance requirements](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstanceRequirements.html) as a set of instance attributes. +2. The **Overrides** configuration block provides EC2 Auto Scaling a choice of instance types your workload can run on. As Spot instances are **spare** EC2 capacity, your workloads should be flexible to run on multiple instance types and availability zones; hence leveraging multiple *spot capacity pools* and making the most out of the available spare capacity. -2. You will use a feature called **Attribute based Instance Type Selection** that lets you express your instance requirements, as a set of attributes including vCPUs, memory, memory per vCPU, processor architecture, instance generation, GPU count and more. Your requirements are automatically translated to all matching instance types whenever EC2 Auto Scaling launches instances. This also allows Auto Scaling groups to automatically use newer generation instance types, as and when they are released. This feature eliminates the undifferentiated heavy lifting of manually selecting, specifying and maintaining instance types list in the Overrides configuration block. To learn more about Attribute based Instance Type Selection, please take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) and this [blog](https://aws.amazon.com/blogs/aws/new-attribute-based-instance-type-selection-for-ec2-auto-scaling-and-ec2-fleet/). You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). +3. You will see in the Overrides block that instead of choosing and specifying instance types, we are specifying [instance requirements](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstanceRequirements.html) as a set of instance attributes. This feature is called **Attribute based Instance Type Selection** that lets you express your instance requirements, as a set of attributes including vCPUs, memory, memory per vCPU, processor architecture, instance generation, GPU count and more. Instance requirements are automatically translated to all matching instance types, whenever EC2 Auto Scaling launches instances. This also allows Auto Scaling groups to automatically use newer generation instance types, as and when they are released and eliminates need to update list of instance types. -{{%expand "Help me understand Auto Scaling group configuration with Attribute based Instance Type Selection" %}} -We are using **Attribute based Instance Type Selection** feature to specify instance attributes, instead of manually selecting and specifying instance types. For the purpose of this workshop, let's assume that your workload is flexible to run on any of the instance types matching below attributes: +{{% notice info %}} +To learn more about Attribute based Instance Type Selection, please take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) and this [blog](https://aws.amazon.com/blogs/aws/new-attribute-based-instance-type-selection-for-ec2-auto-scaling-and-ec2-fleet/). +{{% /notice %}} + +For the purpose of this workshop, let's assume that your workload is flexible to run on any of the instance types matching below attributes: * Instances with 2 vCPUs * Instances with minimum 4 GiB and maximum 16 GiB memory - * Instances which have minimum vCPU to Memory ratio 1:2 and maximum vCPU to Memory ratio of 1:8 * Instances with CPU Architecture of Intel and AMD and no GPU Instances * Instances that belong to current generation - * Excluding Instance families of type: d*,h*,i*,x* and z* - -You can see that above criteria is configured in the *InstanceRequirements* block of the *Overrides* configuration in *asg.json*. Then, the *InstancesDistribution* configuration block determines how EC2 Auto Scaling picks the instance types to use, while at the same time it keeps a balanced number of EC2 instances per Availability Zone. + * Exclude enhanced instance families (z, i and d) that are priced higher than R family +Let's see how above criteria is configured in the *InstanceRequirements* block of the *Overrides* configuration in *asg.json*. +``` +"InstanceRequirements": { + "VCpuCount": { + "Min": 2, + "Max": 2 + }, + "MemoryMiB": { + "Min": 4096, + "Max": 16384 + }, + "CpuManufacturers": [ + "intel", + "amd" + ], + "InstanceGenerations": [ + "current" + ], + "AcceleratorCount": { + "Max": 0 + }, + "ExcludedInstanceTypes": [ + "d*", + "i*", + "z*" + ] + } + +``` +Then, the *InstancesDistribution* configuration block determines how EC2 Auto Scaling picks the instance types to use, while at the same time it keeps a balanced number of EC2 instances per Availability Zone. * **OnDemandAllocationStrategy** is **lowest-price**, which makes Auto Scaling try to launch on-demand instances from the lowest priced instance pools. You must use *lowest-price* as your on-demand allocation strategy with *Attribute based Instance Type Selection* feature. To use the **prioritized** allocation strategy, you must continue to manually add and prioritize your instance types in the Overrides list. This may be required if you have [Reserved Instances](https://aws.amazon.com/ec2/pricing/reserved-instances/) or [Savings Plans](https://aws.amazon.com/savingsplans/) for your baseline capacity, so that Auto Scaling launches the instance type matching your reservations. * **OnDemandBaseCapacity** is set to 2, meaning the first two EC2 instances launched by EC2 AutoScaling will be on-demand. * **OnDemandPercentageAboveBaseCapacity** is set to 0 so all the additional instances will be launched as Spot Instances -* **SpotAllocationStrategy** is **capacity-optimized**, which instructs Auto Scaling to pick the optimal instance type on each Availability Zone based on launch time availability of spare capacity for your instance type selection. With *Attribute based Instance Type Selection*, your Spot allocation strategy must be either *capacity-optimized* or *lowest-price* and to use the *capacity-optimized-prioritized* allocation strategy, you must manually add and prioritize your instance types. -{{% /expand %}} +* **SpotAllocationStrategy** is **capacity-optimized**, which instructs Auto Scaling to pick the optimal instance type on each Availability Zone based on launch time availability of spare capacity for your instance type selection. With *Attribute based Instance Type Selection*, your Spot allocation strategy must be either *capacity-optimized* or *lowest-price*. + +{{% notice note %}} +In case, you have preference for certain instance types, you can use the *capacity-optimized-prioritized* allocation strategy. However, Attribute based Instance Type Selection does not support this strategy. You must manually add your instance types in the order of priority. +{{% /notice %}} -2. You will notice there are placeholder values for **`%TargetGroupArn%`**, **`%publicSubnet1%`** and **`%publicSubnet2%`**. To update the configuration file with the values of the Target Group you created previously and the outputs from the CloudFormation template, execute the following command: + +You will also notice that the **CapacityRebalance** parameter is set to true, which will proactively attempt to replace Spot Instances at elevated risk of interruption. To learn more about the Capacity Relabancing feature, take a look at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html). + +4. You will notice there are placeholder values for **`%TargetGroupArn%`**, **`%publicSubnet1%`** and **`%publicSubnet2%`**. To update the configuration file with the values of the Target Group you created previously and the outputs from the CloudFormation template, execute the following command: ``` sed -i.bak -e "s#%TargetGroupARN%#$TargetGroupArn#g" -e "s#%publicSubnet1%#$publicSubnet1#g" -e "s#%publicSubnet2%#$publicSubnet2#g" asg.json ``` -3. Save the file and create the auto scaling group: +5. Save the file and create the auto scaling group: ``` aws autoscaling create-auto-scaling-group --cli-input-json file://asg.json ``` @@ -44,90 +80,8 @@ This command will not return any output if it is successful. {{% /notice %}} -4. Browse to the [Auto Scaling console](https://console.aws.amazon.com/ec2/autoscaling/home#AutoScalingGroups:view=details) and check out your newly created auto scaling group. Take a look at the instances it has deployed. +6. Browse to the [Auto Scaling console](https://console.aws.amazon.com/ec2/autoscaling/home#AutoScalingGroups:view=details) and check out your newly created auto scaling group. Take a look at the instances it has deployed. # Optional exercise -Now that you have deployed an EC2 Auto Scaling group with Mixed Instance Types and Purchase options, take some time to go through the different configurations in the [console](https://console.aws.amazon.com/ec2autoscaling/home?#/). Click on the **myEC2Workshop** Auto Scaling group and go to the *Instance type requirements* section and click *Edit* button and scroll down to *Preview matching instance types*. Expand to see list of instance types based on your selected instance attributes. Try to edit the instance requirements configured on the Auto Scaling group and see how this preview list changes. - - -{{%expand "Optional-Auto Scaling group configuration with manual instance types list" %}} -**Optionally**, you can use the [EC2 Instance Types console](https://console.aws.amazon.com/ec2/v2/home?#InstanceTypes:) or the [ec2-instance-selector](https://github.com/aws/amazon-ec2-instance-selector) CLI tool to find suitable instance types. To adhere to best practices, minimize Spot interruptions and maximize your chances of launching your target Spot capacity, configure as many different instance types as possible. EC2 Auto Scaling allows you to specify up to 40 different instance types. For the purpose of this workshop, we will use a minimum of 12 different instance types across 3 Availability Zones. That would give you the ability to provision Spot capacity from 36 different capacity pools. - -If you have [Reserved Instances](https://aws.amazon.com/ec2/pricing/reserved-instances/) or [Savings Plans](https://aws.amazon.com/savingsplans/) for your baseline capacity, you can use the **prioritized** allocation strategy for on-demand instances to make AutoScaling try to launch the first instance type of your list. It will skip to the next instance type if for any reason it's unable to launch first one (e.g. temporary unavailability of capacity). - -Please update your *asg.json* configuration file as below, to manually specify instance types and use *prioritized* On-demand allocation strategy: -``` -{ - "AutoScalingGroupName": "myEC2Workshop", - "MixedInstancesPolicy": { - "LaunchTemplate": { - "LaunchTemplateSpecification": { - "LaunchTemplateName": "myEC2Workshop", - "Version": "1" - }, - "Overrides": [ - { - "InstanceType": "m5.large" - }, - { - "InstanceType": "c5.large" - }, - { - "InstanceType": "m4.large" - }, - { - "InstanceType": "c4.large" - }, - { - "InstanceType": "r5.large" - }, - { - "InstanceType": "r4.large" - }, - { - "InstanceType": "m5a.large" - }, - { - "InstanceType": "c5a.large" - }, - { - "InstanceType": "r5a.large" - }, - { - "InstanceType": "m5d.large" - }, - { - "InstanceType": "c5d.large" - }, - { - "InstanceType": "r5d.large" - } - ] - }, - "InstancesDistribution": { - "OnDemandAllocationStrategy": "prioritized", - "OnDemandBaseCapacity": 2, - "OnDemandPercentageAboveBaseCapacity": 0, - "SpotAllocationStrategy": "capacity-optimized" - } - }, - "MinSize": 2, - "MaxSize": 12, - "DesiredCapacity": 4, - "CapacityRebalance": true, - "TargetGroupARNs": [ - "%TargetGroupARN%" - ], - "HealthCheckType": "EC2", - "VPCZoneIdentifier": "%publicSubnet1%,%publicSubnet2%", - "Tags": [ - { - "Key": "SpotInterruptionHandler/enabled", - "Value": "true", - "PropagateAtLaunch": true - } - ] -} -``` -{{% /expand %}} \ No newline at end of file +Now that you have deployed an EC2 Auto Scaling group with Mixed Instance Types and Purchase options, take some time to go through the different configurations in the [console](https://console.aws.amazon.com/ec2autoscaling/home?#/). Click on the **myEC2Workshop** Auto Scaling group and go to the *Instance type requirements* section and click *Edit* button and scroll down to *Preview matching instance types*. Expand to see list of instance types based on your selected instance attributes. Try to edit the instance requirements configured on the Auto Scaling group and see how this preview list changes. \ No newline at end of file diff --git a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json index 25368edd..d232dc84 100644 --- a/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json +++ b/workshops/ec2-auto-scaling-with-multiple-instance-types-and-purchase-options/asg.json @@ -17,10 +17,6 @@ "Min": 4096, "Max": 16384 }, - "MemoryGiBPerVCpu": { - "Min": 2, - "Max": 8 - }, "CpuManufacturers": [ "intel", "amd" @@ -29,13 +25,10 @@ "current" ], "AcceleratorCount": { - "Min": 0, "Max": 0 }, "ExcludedInstanceTypes": [ "d*", - "h*", - "x*", "i*", "z*" ]