All Products
Search
Document Center

Data Management:Integration with Alibaba Cloud CLI

Last Updated:Oct 14, 2024

Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to automate the management of data in Data Management (DMS). This topic provides an example on how to use Alibaba Cloud CLI to call the API operations of DMS.

Before you begin

Familiarize yourself with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?

If you want to perform a complex task by calling API operations in Alibaba Cloud CLI, we recommend that you compile the commands into a shell script and then run the shell script to improve efficiency.

Install Alibaba Cloud CLI

You can also use Cloud Shell provided by Alibaba Cloud to debug the commands that you want to run in Alibaba Cloud CLI. For more information about Cloud Shell, see What is Cloud Shell?

Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has the permissions to manage and access the API operations of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you call API operations or perform routine O&M operations as a Resource Access Management (RAM) user.

Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and a region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see the "Credential types" section of the Configure profiles topic. In this example, AccessKey credentials are used. Perform the following steps:

  1. Create a RAM user and grant the RAM user the permissions to manage Alibaba Cloud services based on your business requirements. For more information, see Create a RAM user and Grant permissions to a RAM user. In this example, the following permissions are granted:

    • AliyunDMSFullAccess: the permissions to manage DMS resources.

    • AliyunCloudShellFullAccess: optional. The permissions to manage Cloud Shell.

      Note

      Grant the AliyunCloudShellFullAccess permission to the RAM user if you want to use Cloud Shell provided by Alibaba Cloud.

  2. Create an AccessKey pair for the RAM user and record the AccessKey ID and AccessKey secret for the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.

  3. Specify a region ID. Alibaba Cloud CLI calls API operations in the specified region. For more information about available regions, see Endpoints.

  4. Use the AccessKey pair of the RAM user to configure AccessKey credentials in the configuration file named AkProfile. For more information, see the "Configuration examples" section of the Configure profiles topic.

Generate a CLI command

  1. Log on to OpenAPI Explorer.

  2. In the left-side search box of the API debugging page, search for the API operation that you want to call.

  3. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right to view the generated sample command that contains the specified parameters.

    image

    • Click the Run Command in CloudShell icon to debug the command in Cloud Shell.

    • Click the Copy icon to copy the sample command to the clipboard. You can also paste the sample command into your local shell to run.

      Note
      • Pay attention to the formats of parameters if you paste the sample command into your local shell for debugging. For more information about the parameter formats in Alibaba Cloud CLI commands, see Parameter formats.

      • If you copy the command to your local shell, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings, and preferentially runs the command in the specified region. You can delete or retain the --region option based on your business requirements. By default, the --region option is added to the sample command that is generated in OpenAPI Explorer.

Sample code

The following sample code uses Alibaba Cloud CLI to call the UpdateUser operation of DMS to update the system role of a user. For more information, see the "Generate a command" section of the Generate and run CLI commands topic.

  1. Run the following command:

    aliyun dms-enterprise UpdateUser --region cn-hangzhou --Uid 21400447956867**** --RoleNames 'ADMIN,DBA'
  2. View the result.

    {
            "RequestId": "B94173EF-0AEE-5B38-84A9-E6BDEF2B84F3",
            "Success": true
    }