You can create scaling groups that contain elastic container instances in the Auto Scaling console. To minimize costs and manage applications deployed on elastic container instances in a simplified manner, you can enable the cost optimization feature of Auto Scaling to automatically scale elastic container instances. This topic describes how to enable the cost optimization feature for scaling groups that contain elastic container instances. This topic also describes the benefits of the cost optimization feature.

Background information

Scaling groups that contain Elastic Compute Service (ECS) instances and scaling groups that contain elastic container instances have several features in common, such as the event-triggered task, lifecycle hook, rolling update, and notification features. For more information, see Compare the features of different types of scaling groups. Scaling groups that contain elastic container instances have several exclusive features, such as image cache and cost optimization features. This topic describes the cost optimization feature.

Billing principles

After you enable the cost optimization feature, Auto Scaling queries the price of elastic container instances, filters ECS instance types that meet your requirements, compares the prices of the ECS instance types, and then selects the ECS instance type that has the lowest price to create elastic container instances. Auto Scaling applies the following rules:
  • If a specified ECS instance type meets your requirements and the price of the ECS instance type is lower than the unit price of elastic container instances, Auto Scaling uses the ECS instance type to create elastic container instances. The elastic container instances are billed based on the price of the ECS instance type. In this case, the cost optimization feature takes effect.
  • If no specified ECS instance type meets your requirements or the price of the ECS instance type that you specified is greater than the unit price of elastic container instances, Auto Scaling does not use the ECS instance type to create elastic container instances. Auto Scaling creates elastic container instances based on vCPU and memory specifications. The elastic container instances are billed based on the unit price of the vCPU and memory specifications. In this case, the cost optimization feature does not take effect.
Note Elastic container instances that are scaled by Auto Scaling can be billed based on the prices of ECS instance types or the prices of vCPU and memory specifications. For more information, see Billing of elastic container instances.

Benefits

The cost optimization feature provides the following benefits:
  • Meets many business requirements: For example, if your business does not require high instance performance, you can deploy your application on elastic container instances of the shared instance type or on burstable instances to reduce resource costs.
  • Minimizes costs: Auto Scaling creates elastic container instances of the specified ECS instance type. In this case, you can enjoy the benefits of reserved instances and savings plans. For more information, see "Cost optimization" in the Billing section of elastic container instances.

Procedure

  1. Create a scaling group that contains elastic container instances.
    For more information, see Step 1: Create a scaling group.
  2. Create a scaling configuration for the scaling group that you just created.
    1. Find the scaling group and click Details in the Actions column.
    2. In the upper part of the page, click the Instance Configuration Sources tab.
    3. On the Scaling Configurations tab, click Create Scaling Configuration.
    4. On the page that appears, configure the parameters based on your business requirements and click Next: System Configurations.
      In this topic, two scaling configurations are created. The cost optimization feature is enabled in one scaling configuration and disabled in the other configuration.
      • For information about how to create a scaling configuration in which the cost optimization feature is disabled, see Create a scaling configuration (Elastic Container Instance).
      • To create a scaling configuration in which the cost optimization feature is enabled, perform the following steps:

        In the Basic Settings step, turn on Enable Cost Optimization in the Container Group Configurations section and specify the instance family that you want to use. For example, you can specify the enterprise-level instance family. For information about other parameter settings, see Create a scaling configuration (Elastic Container Instance).

        The following table describes the entry-level instance family, enterprise-level instance family, and credit entry-level instance family.
        Instance family Description Scenario References
        Entry-level Shared instance types. Instances of this level are the most cost-effective but may not consistently provide stable computing performance. Instances of this level are suitable for business scenarios in which the CPU utilization is low. Shared instance families
        Enterprise-level Instances of this level provide stable performance and dedicated resources Instances of this level are suitable for business scenarios that require high stability. Overview of instance families
        Credit entry-level Burstable instances. CPU credits are used to ensure the stability of computing performance. Instances of this level are suitable for scenarios in which the CPU utilization is low but may fluctuate in specific cases. Overview
    5. Confirm the parameter settings and click Create.
    6. In the message that appears, click Enable Configuration.
  3. Create a scaling rule for the scaling group.
    For more information, see Create a scaling rule.
    Note You can create scheduled tasks and event-triggered tasks for a scaling group based on your business requirements. For more information, see Create a scheduled task and Create event-triggered tasks.
  4. Enable the scaling group.
    For more information, see the "Enable or disable scaling groups" section in the Manage scaling groups topic.

Verify the results

The following figures show the difference between the scale-out results of the scaling group for which the cost optimization feature is disabled and the scaling group for which the cost optimization feature is enabled.

  • If you apply the scaling configuration in which the cost optimization feature is disabled to a scaling group or the cost optimization feature does not take effect, Auto Scaling does not use the specified ECS instance type to create elastic container instances in the scaling group. configuration2
  • If you apply the scaling configuration in which the cost optimization feature is enabled to a scaling group and the cost optimization feature takes effect, Auto Scaling uses the specified ECS instance type to create elastic container instances in the scaling group. configuration

Compare the effects

You can call the DescribeContainerGroupPrice API operation to query the final cost of the elastic container instances that are created by Auto Scaling. In this example, the value of the TradePrice parameter is used as a reference. The value of the TradePrice parameter represents only the cost of the elastic container instances that are created by Auto Scaling in this walkthrough. The cost of elastic container instances for which the cost optimization feature takes effect varies based on your actual configurations.

Cost comparison:
  • If the cost optimization feature is disabled, the value of the TradePrice parameter that is returned is 0.00004085.
  • If the cost optimization feature enabled, the value of the TradePrice parameter that is returned is 0.00003387.

In this case, the cost optimization feature reduced the cost of elastic container instances by 17%.