All Products
Search
Document Center

Auto Scaling:Use a launch template to configure multiple instance types for a scaling group

Last Updated:Dec 01, 2023

You can use a launch template to create Elastic Compute Service (ECS) instances in an efficient manner. Typically, you can use a launch template to specify one instance type. If you enable the Extend Instance Type of Launch Template feature, you can use a launch template to configure multiple instance types at the same time for a scaling group. This topic describes how to use a launch template to configure multiple instance types for a scaling group.

Prerequisites

A launch template is created. The launch template is 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 the trouble of repeatedly configuring ECS instances. You can specify a launch template only for scaling groups of the ECS type. For more information, see Overview.

  • A launch template allows you to specify only one instance type and create instances based on the specified type. For more information, see Create an instance by using a launch template. If you want to configure multiple instance types when you create a scaling group and use a launch template as the instance configuration source, you must enable the Extend Instance Type of Launch Template feature in the Auto Scaling console.

    Note

    The Extend Instance Type of Launch Template feature allows you to configure up to 10 instance types for a scaling group at the same time.

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 Create an instance by using the wizard.

Preemptible instances

Auto Scaling supports only launch templates that use the pay-as-you-go and Preemptible Instance billing methods. If you use 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. In this topic, a pay-as-you-go launch template is used as an example.

  1. Create a launch template.

    For information about how to create a launch template, see Create a launch template.

    In this example, the Billing Method parameter is set to Pay-as-you-go, the Instance Type parameter is set to ecs.g6.large, and the Template Name parameter is set to pay-instance-template. The following figure shows a sample launch template.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 parameters based on your business requirements.

    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 with the Extend Configurations of Launch Template feature enabled.

    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 enable the Extend Configurations of Launch Template feature to configure multiple instance types and specify weights for the instance types. For more information, see Launch template and multi-instance mode.

    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.

    vSwitch

    The default vSwitch is the same as the vSwitch that you want to 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, select Latest Version and retain the default values for other parameters. For information about other parameters, see Create a scaling group.

    Launch template and multi-instance mode

    You can enable the Extend Instance Type of Launch Template feature to configure multiple instance types and specify weights for the instance types. To enable this feature, perform the following operations:

    启动模板.png

    1. In the Create Scaling Group dialog box, set the Select Launch Template parameter to pay-instance-template.

    2. Set the Select Template Version parameter to Latest Version and select the Override Instance Type of Launch Template check box.

    3. Select the Use vCPUs to calculate the capacity of the scaling group check box.

      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. You can select 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 图标 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.伸缩组信息

    Note

    If you only configure a launch template when you create a scaling group, you can enable the Extend Instance Type of Launch Template feature and select the Override Instance Type of Launch Template check box in the Edit Scaling Group dialog box to configure multiple instance types. For more information, see Launch template-only mode.

  5. Trigger a scale-out in the scaling group.

    To trigger scale-outs 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.

View the result

In the following figures, two scaling groups are created. One scaling group uses only a launch template. The other scaling group uses a launch template that has the Extend Instance Type of Launch Template feature enabled.

  • After a scale-out is triggered in the scaling group whose launch template contains ecs.g6.large, Auto Scaling creates only instances of the ecs.g6.large type.template

  • After a scale-out is triggered in the scaling group whose launch template contains ecs.g6.large and has an extended instance type named ecs.g5ne.large, Auto Scaling creates instances of the ecs.g5ne.large.instances

Compare the effects

Compared with the launch template-only mode, the launch template and multi-instance type mode can meet your business requirements in a more flexible manner and increase the success rate of scale-outs. 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 by using another instance type that has sufficient inventory in the zone.