Alibaba Cloud CLI is a flexible and extensible management tool built on the Alibaba Cloud API. You can use it to call APIs and manage your Alibaba Cloud resources. This topic describes how to use Alibaba Cloud CLI to perform a rolling update.
Prerequisites
Alibaba Cloud CLI is installed. For more information, see the installation guide in the Alibaba Cloud CLI documentation.
You have a scaling group with ECS instances.
To update the image of ECS instances in a scaling group, the group must use a scaling configuration.
To install an OOS package on the ECS instances, you must first create the package in CloudOps Orchestration Service (OOS). For more information, see Manage custom extensions in batches.
Background
A rolling update lets you update multiple ECS instances in batches through a single task. For more information, see Rolling update.
Procedure
This topic shows you how to use Alibaba Cloud CLI to update the image of ECS instances in a scaling group, run a script on the ECS instances, and install an OOS package on the ECS instances.
Step 1: Create a RAM user and add permissions
Log on to the RAM console.
Create a RAM user.
In this example, a RAM user named clitest is created. For more information, see Create a RAM user.
In the left-side navigation pane, choose .
Click Create User.
On the Create User page, specify the user settings and click OK.
The following table describes the example settings.
Parameter
Example
Logon Name
example@sample.com
Display name
example
Access Mode
Select Using permanent AccessKey to access.
An AccessKey pair is automatically generated for the RAM user, which you can use to access Alibaba Cloud resources by calling API operations or using other development tools.
On the User Information page, click Download CSV File.
NoteThe AccessKey secret is displayed only when it is created and cannot be retrieved later. Keep your AccessKey secret secure. If an AccessKey pair is lost or compromised, create a new one.
Grant permissions to the RAM user to manage resources.
In the left-side navigation pane, choose .
Find the RAM user clitest that you created and click Add Permissions in the Actions column.
On the Add Permissions page, select the required permissions for the rolling update and click OK.
The following table describes the example settings.
Parameter
Example
Resource Range
Retain the default value Account.
Principal
Retain the default value example@sample.com.
Policies
Select the following system policies:
AliyunECSFullAccess: Grants permissions to manage ECS resources, including ECS instances.
AliyunESSFullAccess: Grants permissions to manage Auto Scaling resources, including scaling groups.
AliyunOOSFullAccess: Grants permissions to manage CloudOps Orchestration Service (OOS) resources, including executions.
AliyunOSSFullAccess: Grants permissions to manage Object Storage Service resources, including buckets.
Step 2: Configure and verify Alibaba Cloud CLI
For more information about the configuration items, see the Configure Alibaba Cloud CLI section in the Alibaba Cloud CLI documentation.
Open the command-line tool on your local machine.
Configure Alibaba Cloud CLI.
Run the following command to open the configuration file.
aliyun configureEnter information such as the AccessKey ID and AccessKey secret as prompted.

Run the following command to verify your Alibaba Cloud CLI configuration.
aliyun ecs DescribeRegionsThis command queries the supported regions. If a list of regions is returned, the configuration is correct. The following figure shows a sample output.

Step 3: Perform a rolling update
This step provides sample commands to update the image of ECS instances in a scaling group, run a script on the ECS instances, and install an OOS package on the ECS instances.
Enter the Alibaba Cloud CLI command to perform the rolling update.
For more information about the OOS template parameters that are used in the sample code, see Template parameters.
This example updates the image of the ECS instances in the scaling group to Alibaba Cloud Linux 2.1903 LTS 64-bit.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup --Parameters "{ \"invokeType\": \"invoke\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"scalingConfigurationId\": \"asc-bp1bx8mzur534edp****\", \"imageId\": \"aliyun_2_1903_x64_20G_alibase_20200529.vhd\", \"sourceImageId\": \"centos_7_8_x64_20G_alibase_20200717.vhd\", \"OOSAssumeRole\": \"\", \"enterProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"exitProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"The following sample command for script execution runs the Shell commands df -h and ifconfig on ECS instances in a scaling group to view the disk and network configuration information of the instances.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByRunCommandInScalingGroup --Parameters "{ \"invokeType\": \"invoke\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"commandType\": \"RunShellScript\", \"invokeScript\": \"df -h\nifconfig\", \"rollbackScript\": \"df -h\nifconfig\", \"OOSAssumeRole\": \"\", \"exitProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"enterProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"This example installs the WordPress package that is created in OOS on the ECS instances in the scaling group.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByConfigureOOSPackage --Parameters "{ \"invokeType\": \"invoke\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"packageName\": \"wordpress\", \"packageVersion\": \"v4\", \"action\": \"install\", \"OOSAssumeRole\": \"\", \"enterProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"exitProcess\": [ \"ScaleIn\", \"ScaleOut\", \"HealthCheck\", \"AlarmNotification\", \"ScheduledAction\" ], \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"
View the execution details.
Running the rolling update command automatically creates an OOS execution. You can use the returned execution ID to view details, such as the result and output. The following example shows how to obtain the execution ID and view the execution details of a script.
Find the execution ID of the rolling update in the returned information.
The following figure shows a sample execution ID.

Run the following Alibaba Cloud CLI command to view the execution details.
aliyun oos ListExecutions --ExecutionId exec-40e2e17ef7e04****The following figure shows sample execution details.

Rollback: Handle exceptions
If an exception occurs during a rolling update, or if you need to revert to a previous configuration, you can perform a rollback. A rollback restores the original configuration of the ECS instances in the scaling group. This step provides a sample command to roll back a rolling update.
Find the execution ID of the rolling update in the returned information.
The following figure shows a sample execution ID.

Enter the Alibaba Cloud CLI command to perform the rollback.
For more information about the OOS template parameters that are used in the sample code, see Template parameters.
NoteWhen you perform a rollback, OOS automatically filters the ECS instances to be rolled back and suspends and resumes the scaling processes of the scaling group based on the rolling update. This allows you to omit certain parameters.
This example rolls back the image of the ECS instances to CentOS 7.8 64-bit.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup --Parameters "{ \"invokeType\": \"rollback\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"scalingConfigurationId\": \"asc-bp1bx8mzur534edp****\", \"sourceImageId\": \"centos_7_8_x64_20G_alibase_20200717.vhd\", \"sourceExecutionId\": \"exec-83dba59be77d430****\", \"OOSAssumeRole\": \"\", \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"The following example command executes a rollback script on an ECS instance. This example uses the Shell commands df -h and ifconfig. You can replace the script as needed.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByRunCommandInScalingGroup --Parameters "{ \"invokeType\": \"rollback\", \"commandType\": \"RunShellScript\", \"rollbackScript\": \"df -h\nifconfig\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"sourceExecutionId\": \"exec-40e2e17ef7e046****\", \"OOSAssumeRole\": \"\", \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"This example rolls back an OOS package installation by installing a previous version of the WordPress package on the ECS instances.
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByConfigureOOSPackage --Parameters "{ \"invokeType\": \"rollback\", \"scalingGroupId\": \"asg-bp18p2yfxow2dloq****\", \"packageVersion\": \"v3\", \"packageName\": \"wordpress\", \"sourceExecutionId\": \"exec-f4e61f2f21fe490****\", \"OOSAssumeRole\": \"\", \"batchNumber\": 2, \"batchPauseOption\": \"Automatic\" }"
View the execution details.
When you run the CLI command to perform a rollback, an execution is also automatically created in OOS. You can also use the method described in Step 3 to view the details of the execution, such as the result and output.
Template parameters
This section describes the parameters of the public templates that are used in the examples.
Table 1. ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup parameters
Parameter | Description |
invokeType | The task type. Valid values:
|
scalingGroupId | The ID of the target scaling group. |
scalingConfigurationId | The ID of the active scaling configuration in the scaling group. |
imageId | The ID of the new image for the update. |
sourceImageId | The ID of the original image to restore during a rollback. |
OOSAssumeRole | The RAM role that is used to perform the task. Default value: OOSServiceRole. |
enterProcess | The scaling process that is suspended when the task starts. |
exitProcess | The scaling process that is resumed when the task is complete. |
batchNumber | The number of batches to divide the ECS instances into for this task. Each batch must contain at least one instance. |
batchPauseOption | The pause setting for the task. Valid values:
|
sourceExecutionId | The ID of the original execution to roll back. This parameter is required for rollbacks. |
For more parameter details, you can also visit the OOS console. To view the parameter descriptions in the China (Hangzhou) region, see ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup.
Table 2. ACS-ESS-RollingUpdateByRunCommandInScalingGroup parameters
Parameter | Description |
invokeType | The task type. Valid values:
|
scalingGroupId | The ID of the target scaling group. |
commandType | The type of script that you want to run. The value RunShellScript indicates a shell script. |
invokeScript | The script that you want to run on the ECS instances during a rolling update. |
rollbackScript | The script that you want to run on the ECS instances during a rollback. |
OOSAssumeRole | The RAM role that is used to perform the task. Default value: OOSServiceRole. |
enterProcess | The scaling process that is suspended when the task starts. |
exitProcess | The scaling process that is resumed when the task is complete. |
batchNumber | The number of batches to divide the ECS instances into for this task. Each batch must contain at least one instance. |
batchPauseOption | The pause setting for the task. Valid values:
|
sourceExecutionId | The ID of the original execution to roll back. This parameter is required for rollbacks. |
For more parameter details, you can also visit the OOS console. To view the parameter descriptions in the China (Hangzhou) region, see ACS-ESS-RollingUpdateByRunCommandInScalingGroup.
Table 3. ACS-ESS-RollingUpdateByConfigureOOSPackage parameters
Parameter | Description |
invokeType | The task type. Valid values:
|
scalingGroupId | The ID of the target scaling group. |
packageName | The name of the package. |
packageVersion | The version of the package. |
action | The action to perform on the package. Valid values:
Default value: install. |
OOSAssumeRole | The RAM role that is used to perform the task. Default value: OOSServiceRole. |
enterProcess | The scaling process that is suspended when the task starts. |
exitProcess | The scaling process that is resumed when the task is complete. |
batchNumber | The number of batches to divide the ECS instances into for this task. Each batch must contain at least one instance. |
batchPauseOption | The pause setting for the task. Valid values:
|
sourceExecutionId | The ID of the original execution to roll back. This parameter is required for rollbacks. |
For more parameter details, you can also visit the OOS console. To view the parameter descriptions in the China (Hangzhou) region, see ACS-ESS-RollingUpdateByConfigureOOSPackage.