A launch template helps you create Elastic Compute Service (ECS) instances in an efficient manner. However, only one instance type can be specified by using a single launch template. If you want to specify multiple instance types for a scaling group, you can use a launch template together with the Extend Configurations of Launch Template feature. This topic describes how to specify multiple instance types for a scaling group when you configure a launch template for the scaling group.

Prerequisites

A launch template is created. The launch template can be used to create ECS instances. For more information, see Create a launch template or CreateLaunchTemplate.

Background information

  • Alibaba Cloud ECS provides the launch template feature. A launch template contains configurations of ECS instances. You can use a launch template to prevent repeated ECS instance configuration. You can specify a launch template only for scaling groups of the ECS type. For more information, see Overview.
  • If you configure a launch template for a scaling group, you can specify only one instance type. You can create ECS instances based on the instance type that you specified in the launch template. For more information, see Create an instance by using a launch template. If you want to specify multiple instance types for a scaling group, you must modify the launch template that you configured for the scaling group and use the Extend Configurations of Launch Template feature in the Auto Scaling console.
    Note The Extend Configurations of Launch Template feature allows you to specify up to 10 instance types for a scaling group.

Procedure

The following table describes the billing methods that are supported by the launch template feature.
Billing method Description References
Subscription You must pay an upfront fee for subscription launch templates. The subscription period can be accurate to the week.

Take note that Auto Scaling does not support subscription launch templates. If you configure a subscription launch template as the instance configuration source when you create a scaling group, Auto Scaling replaces the subscription launch template with a pay-as-you-go launch template.

Subscription
Pay-as-you-go You can use launch templates first and pay for the launch templates afterwards. The billing cycle is accurate to the second. The pay-as-you-go billing method allows you to purchase and release resources flexibly based on your business requirements. Pay-as-you-go
Preemptible instance You can use preemptible instances first and pay for the instances afterwards. Compared with the pay-as-you-go billing method, this billing method offers discounts. Take note that preemptible instances may be automatically released due to a spot price change or insufficient resources.

If you set the Billing Method parameter to Preemptible Instance, you must configure the Use Duration and Maximum Price for Instance Type parameters. For more information, see Step 2 in Select an instance type and complete the relevant configurations.

Preemptible instances

You can configure a launch template that is used to create pay-as-you-go or preemptible instances as the instance configuration source when you create a scaling group. If you configure a launch template that is used to create subscription instances as the instance configuration source when you create a scaling group, Auto Scaling automatically replaces the template with a pay-as-you-go launch template. In this topic, a pay-as-you-go launch template is used as an example.

  1. Create a launch template.
    For more information, see Create a launch template.
    In the following figure, a launch template named pay-instance-template is displayed. The Billing Method parameter of the launch template is set to Pay-as-you-go, and the Instance Type parameter is set to ecs.g6.large.template
  2. On the Launch Templates page of the ECS console, find the pay-instance-template launch template and choose Create Auto Scaling Group > Use Latest Version in the Actions column.
    You can also choose Create Auto Scaling Group > Use Default Version in the Actions column based on your business requirements.
  3. In the Create Scaling Group dialog box, configure the required parameters.
    In this example, two scaling groups are created. One scaling group is created by using a launch template, and the other scaling group is created by using a launch template and the Extend Configurations of Launch Template feature.
    If you set the Instance Configuration Source parameter to Launch Templates when you create a scaling group, Auto Scaling automatically populates the settings of the parameters that are described in the following table. If you set the Instance Configuration Source parameter to Create from Scratch when you create a scaling group, you must manually configure the parameters.
    Note We recommend that you retain the default values of the parameters described in the following table.
    Parameter Description
    Instance Configuration Source The default value of this parameter is Launch Templates. In this example, the pay-instance-template launch template is used. The default value of the Select Template Version parameter is Latest Version.

    If you want to use the template in different business scenarios, you can use the Extend Configurations of Launch Template feature to specify multiple instance types and specify weights for the instance types. For more information, see Launch template + Multiple instance types.

    Network Type The default network type is the same as the network type of the launch template.
    VPC The default virtual private cloud (VPC) is the same as the VPC in which you want to create ECS instances by using the launch template.
    Select vSwitch The default vSwitch is the same as the vSwitch that you associate with the ECS instances that you want to create by using the launch template.

    Launch template-only mode

    In the Select Template Version section, retain the default values. Do not click Extend Configurations of Launch Template (Used to support multiple instance types and weighted capacity for the scaling group). For information about other parameters, see Create a scaling group.

    Launch template + Multiple instance types mode

    In the Select Template Version section, the default value is Latest Version. You can use the Extend Configurations of Launch Template feature to specify multiple instance types. To use the Extend Configurations of Launch Template feature, perform the following steps:Extend Configurations of Launch Template
    1. In the Create Scaling Group dialog box, set the Select Launch Template parameter to pay-instance-template.
    2. Retain the default value Latest Version for the Select Template Version parameter and then click Extend Configurations of Launch Template (Used to support multiple instance types and weighted capacity for the scaling group).
    3. Select Use vCPUs to calculate the capacity of the scaling group.
      Auto Scaling calculates the capacity of the scaling group based on the number of vCPUs. In the Selected Instance Types section, you can view the weights of selected instance types. If you reset the number of vCPUs, Auto Scaling recalculates the capacity of the scaling group based on the new number of vCPUs. In this case, Auto Scaling may trigger a scaling activity in the scaling group. You can also use other instance performance metrics, such as memory size, to create custom methods to calculate the capacity of your scaling group. For more information, see Use performance metrics to measure Auto Scaling.
    4. In the Available Instance Types section, find the instance types that you want to select and click the icon icon.
      For example, you can select the following instance types: ecs.g5ne.large and ecs.g6.large. To reduce the risk of insufficient instance types, we recommend that you select multiple instance types by using one of the following options: Select All Instance Types, Recommended by Instance Type, and Recommended by vCPU.
      Note In the Selected Instance Types section, you can view the selected instance types. You can click the Move icon icon to reduce the number of the selected instance types.
    5. Configure other parameters of the scaling group.
      For information about other parameters, see Create a scaling group.
  4. Click OK.
    After you create the scaling group, you can view information about the launch template in the Instance Configuration Source column of the scaling group on the Scaling Groups page. Scaling group information
    Note If you only configure a launch template when you create a scaling group, you can click Extend Configurations of Launch Template (Used to support multiple instance types and weighted capacity for the scaling group) in the Edit Scaling Group dialog box to specify multiple instance types. For more information, see Launch template + Multiple instance types mode in Step 3.
  5. Trigger scaling activities.
    To trigger scaling activities in a scaling group, you can use methods such as configuring a minimum number of instances, configuring an expected number of instances, and executing scaling rules.

Check the results

In the following figures, two scaling groups are created. A launch template is configured for one scaling group. A launch template is configured and multiple instance types are specified for the other scaling group.
  • After a scale-out activity is triggered in the scaling group for which a pay-as-you-go launch template that contains the ecs.g6.large instance type is configured, Auto Scaling can create only instances of the ecs.g6.large instance type. template
  • After a scale-out activity is triggered in the scaling group for which a pay-as-you-go launch template that contains the ecs.g6.large instance type is configured and the ecs.g5ne.large instance type is specified, Auto Scaling can create instances of the ecs.g5ne.large instance type.instances

Compare the effects

Compared with the Launch template-only mode, the Launch template + Multiple instance types mode can meet your business requirements in a more flexible manner and increase the success rate of scale-out activities. For example, if you specify multiple instance types and one of the instance types in a zone does not have sufficient inventory, Auto Scaling creates ECS instances in another zone by using instance types that have sufficient inventory.