Background information
In some scenarios, you may need to change the billing method of multiple Elastic Compute Service (ECS) instances from subscription to pay-as-you-go or from pay-as-you-go to subscription based on your business requirements. You can manually change the billing method of multiple ECS instances one by one. However, the manual operations are inefficient and prone to errors. This topic describes how to change the billing method of multiple ECS instances at a time by using CloudOps Orchestration Service (OOS). ECS supports the subscription and pay-as-you-go billing methods. For more information, see Subscription and Pay-as-you-go.
Prerequisites
For information about the prerequisites for changing the billing method of an ECS instance from subscription to pay-as-you-go, see Change the billing method of an instance from subscription to pay-as-you-go.
For information about the prerequisites for changing the billing method of an ECS instance from pay-as-you-go to subscription, see Change the billing method of an instance from pay-as-you-go to subscription.
Procedure
Go to the OOS console>Automated Task>Public Template page.
Enter ACS-ECS-BulkyModifyInstanceChargeType in the search box and click the Search icon. Click Create Execution for the ACS-ECS-BulkyModifyInstanceChargeType template.
On the Create Task page, configure the required parameters in the Basic Information step, and click Next Step: Parameter Settings.
In the Parameter Settings step, configure the following parameters:
InstanceChargeType: the new billing method of the instances.
Period: the subscription duration of the instances. This parameter is required if you select PrePaid as InstanceChargeType. If you select Week as PeriodUnit, the valid values of the Period parameter are 1 to 4. If you select Month as PeriodUnit, the valid values of the Period parameter are 1 to 12, 24, 36, 48, and 60.
PeriodUnit: the time unit of the subscription duration. This parameter is required if you select PrePaid as InstanceChargeType.
IncludeDataDisks: specifies whether to change the billing method of all data disks attached to the instances from pay-as-you-go to subscription. This parameter is required if you select PrePaid as InstanceChargeType.
NetworkChargeType: the new billing method for network usage.
RegionId: the ID of the region.
TargetInstance: the instances for which you want to change the billing method.
RateControl: optional. The concurrency configuration of the execution.
OOSAssumeRole: optional. The Resource Access Management (RAM) role to be assumed by OOS.

Click Next Step: OK. In the OK step, click Create.
On the Task Execution Management page, find the created execution.
If the execution is in the Running state, the billing method of the specified ECS instances is being changed.
When the state of the execution changes to Success, the billing method of the specified ECS instances is changed. You can view the new billing method of the ECS instances on the Instance page of the ECS console.
To view the details about the process of changing the billing method of the ECS instances, click Details in the Actions column to view the execution logs. Then, you can view the execution progress and status in real time.
Appendix
Public template ACS-ECS-BulkyModifyInstanceChargeType
FormatVersion: OOS-2019-06-01
Description:
en: Bulky modify instance charge type
name-en: ACS-ECS-BulkyModifyInstanceChargeType
categories:
- instance_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Type: Json
Label:
en: TargetInstance
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: ALIYUN::ECS::Instance
RegionId: regionId
instanceChargeType:
Label:
en: InstanceChargeType
Type: String
AllowedValues:
- PostPaid
- PrePaid
Default: PostPaid
periodUnit:
Label:
en: PeriodUnit
Type: String
AllowedValues:
- Week
- Month
Default: Month
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${instanceChargeType}
- PostPaid
period:
Description:
en: The period of the instance
Label:
en: Period
Type: Number
Default: 1
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${instanceChargeType}
- PostPaid
includeDataDisks:
Description:
en: Specifies whether to change the billing method of all data disks attached to the instance from pay-as-you-go to subscription
Label:
en: IncludeDataDisks
Type: Boolean
Default: false
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${instanceChargeType}
- PostPaid
networkChargeType:
Label:
en: NetworkChargeType
Type: String
AllowedValues:
- PayByBandwidth
- PayByTraffic
- ''
Default: PayByTraffic
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances
Action: ACS::SelectTargets
Properties:
ResourceType: ALIYUN::ECS::Instance
RegionId: '{{ regionId }}'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: Instances.Instance[].InstanceId
- Name: modifyInstanceChargeType
Description:
en: Modify instance charge type
Action: ACS::ECS::ModifyInstanceChargeType
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
instanceChargeType: '{{ instanceChargeType }}'
networkChargeType: '{{ networkChargeType }}'
period: '{{ period }}'
periodUnit: '{{ periodUnit }}'
includeDataDisks: '{{ includeDataDisks }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- instanceChargeType
- period
- periodUnit
- includeDataDisks
- networkChargeType
Label:
default:
en: Choose the parameter of instnace charge type
- Parameters:
- regionId
- target
Label:
default:
en: Select ECS Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
en: Control Options