All Products
Search
Document Center

Data Management:Use Alibaba Cloud CLI to call the API operations of DMS

Last Updated:Jan 15, 2025

This topic describes how to use Alibaba Cloud CLI to call the API operations of Data Management. For example, call the Data Management (DMS)UpdateUser operation to update the system role.

Before you begin

Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to automate management and maintenance of resources in Data Management. For more information, see What is Alibaba Cloud CLI?

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

Step 1: Install Alibaba Cloud CLI

Alibaba Cloud CLI is pre-installed in Cloud Shell. Cloud Shell automatically configures an identity credential for you. You can use Cloud Shell to debug the commands that you want to run in Alibaba Cloud CLI. For more information, see What is Cloud Shell?

Step 2: Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has permissions to manage and access the APIs of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you create a Resource Access Management (RAM) user, grant the required permissions to the RAM user based on the principle of least privilege, and then use the RAM user to call API operations. For more information about permission policies that are supported by Data Management, see DMS custom policies.

Before you use Alibaba Cloud CLI, you must specify information, such as identity credentials and a region ID, in Alibaba Cloud CLI. Alibaba Cloud CLI supports various types of identity credentials. For more information, see the "Credential types" section of the Credential types topic. Alibaba Cloud CLI allows you to use the AccessKey pair of a RAM user to configure identity credentials. If you want to use the AccessKey pair of a RAM user, perform the following steps:

  1. Create a RAM user and create an AccessKey pair for the RAM user to configure identity credentials. For more information, see Create a RAM user and Create an AccessKey.

  2. Grant the required permissions to the RAM user. In this example, the AliyunDMSFullAccess policy is attached to the RAM user. The policy grants the permissions to manage Data Management resources. For more information, see Grant permissions to a RAM user.

  3. Obtain the ID of the region that you want to use to configure identity credentials. Alibaba Cloud CLI uses the region ID that you specify to initiate API calls. For more information about the regions supported by Data Management, see Endpoints.

    Note

    When you use Alibaba Cloud CLI, you can use the --region option to run a command in a specific region. If you use the option, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings. For more information, see Command line options for API calls.

  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.

Step 3: Generate a CLI command

  1. In OpenAPI Explorer, call the UpdateUser operation.

    image

  2. On the Parameters tab, configure the request parameters. Then, click the CLI Example tab to view the generated sample CLI command.

  3. Copy the CLI command or debug the CLI command in Cloud Shell.

    • Click the image icon to run the command in Cloud Shell. You can quickly debug the command in the Cloud Shell window.

    • Click the image icon to copy the sample command to the clipboard. Then, paste the sample command into your on-premises shell to run the sample command.

    Note

    When you paste the CLI command into your on-premises shell for debugging, take note of the parameter formats. For information about the parameter formats required by Alibaba Cloud CLI, see Parameter formats.

    By default, OpenAPI Explorer adds the --region option to the generated CLI command. When you copy the command to your local shell, Alibaba Cloud CLI ignores the region information in the default identity credential configurations and environment variable settings, and preferentially uses the specified region to run the command. You can delete or retain this option based on your business requirements.

Step 4: Call the API operations of Data Management

Example 1: Query the API operations

The following code provides an example on how to use the --help option to query the Data Management API operations that can be called in Alibaba Cloud CLI. For more information, see List of operations by function.

  1. Run the following command:

    aliyun dms-enterprise --help
  2. View the command output.

    image

Example 2: Update the system role

The following code provides an example on how to use Alibaba Cloud CLI to call the UpdateUser operation of Data Management to update the system role of a user. For more information, see UpdateUser.

  1. Run the following command:

    aliyun dms-enterprise UpdateUser --Uid 21400447956867**** --RoleNames 'ADMIN,DBA'
  2. View the command output.

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

    If an error message is returned after you call an API operation of Data Management, check whether the request parameters and the values of the request parameters are valid based on the error code.

    You can also perform self-service diagnostics based on the returned request ID or SDK error information on the OpenAPI problem diagnosis page.