Use Alibaba Cloud CLI to manage MSE

Updated at: 2024-11-11 02:33

Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to implement automated management and maintenance of Microservices Engine (MSE). This topic describes how to use Alibaba Cloud CLI to call the API operations of MSE. In this example, the ListTagResources operation is called to query tags.

Before you start

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

Step 1: Install Alibaba Cloud CLI

You must install Alibaba Cloud CLI before you can use Alibaba Cloud CLI. You can install Alibaba Cloud CLI on the Windows, Linux, and macOS operating systems. For more information about how to install Alibaba Cloud CLI based on the operating system that you use, see the following topics:

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

Step 2: Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has the 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 RAM identity, grant the required permissions to the RAM identity based on the principle of least privilege, and then use the RAM identity to call API operations. For more information about permission policies that are supported by MSE, see System policies for MSE and Custom policies for MSE.

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 identity credentials. For more information, see the "Credential types" section in Configure profiles. In this example, AccessKey credentials are used. Procedure:

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

  2. Grant the required permissions to the RAM user. In this example, attach the AliyunMSEReadOnlyAccess policy to the RAM user to grant the RAM user the read-only permissions on MSE. For more information, see Grant permissions to a RAM user.

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

    Note

    When you use Alibaba Cloud CLI, you can specify the --region option to run a command in a specific region. If you specify this 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 and the obtained region ID to configure identity credentials in the AkProfile configuration file. For more information, see the "Configuration examples" section in Configure profiles.

Step 3: Generate a CLI command

  1. Go to the ListTagResources debugging page in OpenAPI Explorer.

    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 start Cloud Shell and debug the CLI command in Cloud Shell.

    • Click the image icon to copy the CLI command to the clipboard. You can paste the CLI command into your local shell tool to run the CLI command.

    Note

    When you paste the CLI command into your local shell for debugging, take note of the parameter formats. For more 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 settings and environment variables, and runs the command in the region specified by the option. You can delete or retain the option based on your business requirements.

Step 4: Call API operations of MSE

Example 1: Query the MSE API operations that can be called in Alibaba Cloud CLI

This example uses the --help option to query the MSE API operations that can be called in Alibaba Cloud CLI. You can also view the supported API operations in List of operations by function.

  1. Run the following command:

    aliyun mse --help
  2. View the command output.

    image

Example 2: Query tags

This example uses Alibaba Cloud CLI to call the ListTagResources operation of MSE to query information about the resource whose ID is mse-cn-7pp2st2**** and the tags added to the resource.

  1. Run the following command:

    aliyun mse ListTagResources --RegionId 'cn-hangzhou' --ResourceType CLUSTER --ResourceId.1 'mse-cn-7pp2st2****' 
  2. View the command output.

    {
      "NextToken": "AAAAAV3MpHK1AP0pfERHZN5pu6ng3BeUyo2zbY5wgL1DBa2T",
      "RequestId": "92ED7C9C-84A2-595F-87FE-354F84C0F739",
      "Message": "The request is successfully processed.",
      "ErrorCode": "mse-100-000",
      "Success": true,
      "TagResources": {
        "TagResource": [
          {
            "ResourceId": "mse-cn-7pp2st2****",
            "ResourceType": "cluster",
            "TagValue": "prd",
            "TagKey": "env"
          }
        ]
      }
    }
    Note

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

    You can also use Alibaba Cloud OpenAPI Diagnostics to perform self-service diagnostics based on the returned request ID or SDK error information.

  • On this page (1, T)
  • Before you start
  • Step 1: Install Alibaba Cloud CLI
  • Step 2: Configure Alibaba Cloud CLI
  • Step 3: Generate a CLI command
  • Step 4: Call API operations of MSE
  • Example 1: Query the MSE API operations that can be called in Alibaba Cloud CLI
  • Example 2: Query tags
Feedback