All Products
Search
Document Center

CloudOps Orchestration Service:Trigger temporary bandwidth upgrades based on alerts for ECS instances

Last Updated:Mar 17, 2025

This topic describes how to use alert O&M tasks to monitor the status of bandwidth and temporarily upgrade bandwidth under specific conditions.

Overview

If the bandwidth of your subscription Elastic Compute Service (ECS) instances cannot meet your business requirements, you can upgrade the bandwidth of your ECS instances to improve network performance. However, the time when the bandwidth is to be upgraded and the condition under which the bandwidth is to be upgraded vary in each bandwidth upgrade. It is time-consuming, labor-intensive, and error-prone if you manually upgrade the network bandwidth every time. You can also permanently upgrade the network bandwidth of your ECS instances. This saves time but increases costs. In this case, you can use CloudOps Orchestration Service (OOS) to create alert O&M tasks to trigger temporary bandwidth upgrades for ECS instances. For example, you can set a trigger rule to temporarily upgrade bandwidth when the bandwidth usage exceeds the threshold. This helps you save time, labor, and costs.

Procedure

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Automated O&M > My Templates. On the My Templates page, click Create Template. On the Create Template page, enter a template name and click the YAML or JSON tab based on the script type. Copy the script that is provided in Appendix 1 and paste the script into the code editor. The script is used to create a template for upgrading bandwidth. Then, click Create Template.

  3. In the left-side navigation pane, choose Automated O&M > Alert and Event O&M and click Create.

  4. Go to the Trigger Rule section.

  5. Select ECS from the Service type drop-down list, and select a trigger condition in the Rule Description drop-down list. In this example, VPC-Internet Outflow Bandwidth Usage is selected and the threshold is set to 80%. This way, a temporary bandwidth upgrade is triggered if the usage of the Internet outbound bandwidth over a virtual private cloud (VPC) is greater than 80%. Set the Mute Period parameter to a period longer than the specified cycle of bandwidth upgrade. This prevents repeated upgrades if alerts are repeatedly generated.

  6. In the Resources Alerted section, select one or more instances whose bandwidth you want to monitor.

    image

  7. In the Select Template section, select My Template from the drop-down list next to the search box, and select the template that you created in Step 3.

  8. In the Configure Template Parameters section, configure parameters as required. The default value of the InstanceId parameter is $.instanceId. In this case, the ID of the instance whose bandwidth usage exceeds the threshold is automatically obtained. In addition, you must select a RAM role that is authorized to modify bandwidth configurations and use OOS. The following script shows the JSON content of the policy that grants permissions to the RAM role. For more information, see Grant RAM permissions to OOS.

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:ModifyInstanceNetworkSpec"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

  1. Click Create. In the dialog box that appears, confirm the parameters and click OK.

  2. View the execution. If a bandwidth upgrade is triggered, you can find that a child execution is created and run, and the bandwidth configurations of the selected instances are upgraded.

Appendix 1

If you create a template for bandwidth upgrade based on the following script, the validity period of the temporary bandwidth is within the range of 3-4 hours by default. If the start time of an upgrade is 3 minutes before the hour, the valid period is 240 minutes. If start time of an upgrade is more than 3 minutes before the hour, the validity period is within the range of 181-239 minutes. You can also change the maximum validity period based on your business requirements. To change the maximum validity period, modify the number 14580 (4 hours + 3 minutes) in the template. For example, if you want to set the validity period to 7-8 hours, change the number 14580 to 28980.

FormatVersion: OOS-2019-06-01
Description:
  en: ' Temporarily upgrade bandwidth for an ECS instance.'
  zh-cn: the description in Chinese.
  name-en: ECS-TemporaryUpgradeInternetBandwidth
  name-zh-cn: the description in Chinese.
Parameters:
  RegionId:
    Type: String
    Description:
      en: The ID of region.
      zh-cn: the description in Chinese. 
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  InstanceId:
    Type: String
    Description:
      en: The ID of the ECS instance.
      zh-cn: the description in Chinese.
    Default: "$.instanceId"
  MaxBandwidthOut:
    Description:
      en: The bandwidth to be temporarily upgraded. For example, if you specify a value of 8, the bandwidth will be temporarily upgraded to 8 MB/s. Set this parameter to a  value that is greater than the current bandwidth.
      zh-cn: the description in Chinese.
    Type: Number
    MinValue: 0
    MaxValue: 200
    Default: 2
  OOSAssumeRole:
    Description:
      en: The RAM role to be assumed by OOS.
      zh-cn: the description in Chinese. 
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: TemporaryUpgradeInternetBandwidth
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Modifies the temporary bandwidth of the instances.
      zh-cn: the description in Chinese. 
    Properties:
      Service: ECS
      API: ModifyInstanceNetworkSpec
      Parameters:
        RegionId: '{{ RegionId }}'
        InstanceId: '{{ InstanceId }}'
        InternetMaxBandwidthOut: '{{ MaxBandwidthOut }}'
        StartTime:
          'Fn::FormatUTCTime':
            - 'Fn::AddSecond':
                - '{{ ACS::CurrentUTCTime }}'
                - 180  # 3min
            - '%Y-%m-%dT%H:%MZ'
        EndTime:
          'Fn::FormatUTCTime':
            - 'Fn::AddSecond':
                - '{{ ACS::CurrentUTCTime }}'
                -14580 # 14580 is calculated by 3 minutes (180 seconds) plus 4 hours (14,400 seconds). This is the default value of the maximum validity period of the temporary bandwidth. The validity period is within the range of 181-240 minutes. If the start time of an upgrade is 3 minutes before the hour, the validity period is 240 minutes. If the start time of an upgrade is more than 3 minutes before the hour, the validity period is within the range of 181-239 minutes. 
            - '%Y-%m-%dT%HZ'