All Products
Search
Document Center

Resource Management:CLI reference

Last Updated:Jun 04, 2026

Uses the Resource Sharing ListResourceShares operation to show how to call Resource Sharing API operations from Alibaba Cloud CLI.

Prerequisites

  • Alibaba Cloud CLI is a command-line tool built on OpenAPI that automates Resource Sharing management. What is Alibaba Cloud CLI.

  • Alibaba Cloud CLI 3.0.282 or later is required for Resource Sharing OpenAPI version 2020-01-10. Update to the latest version for full support.

Step 1: Install Alibaba Cloud CLI

Install Alibaba Cloud CLI for your operating system:

Cloud Shell comes with Alibaba Cloud CLI pre-installed and configures credentials automatically. Debug CLI commands in Cloud Shell. What is Cloud Shell?.

Step 2: Configure Alibaba Cloud CLI

Important

Your root account has full permissions for all OpenAPI operations, which poses a high security risk. We strongly recommend that you create a RAM identity with least-privilege permissions and use it to call API operations. For information about the permission policies that Resource Sharing supports, see System policies for Resource Manager and Authorization for Resource Sharing.

Configure an identity credential and region ID for Alibaba Cloud CLI. Multiple credential types are supported (Configure and manage credentials). This example uses an AccessKey credential.

  1. Create a RAM user and an AccessKey. Create a RAM user. Create an AccessKey.

  2. Attach the AliyunResourceSharingReadOnlyAccess policy to the RAM user for read-only access to Resource Sharing. Manage RAM user permissions.

  3. Obtain a region ID. Available Resource Sharing regions are listed in Endpoints.

    Note

    The --region option overrides the region in your default credential profile and environment variables. Command-line options.

  4. Configure an AccessKey-based credential profile named AkProfile using the RAM user's AccessKey and region ID. Configure and manage credentials.

Step 3: Generate a sample CLI command

  1. In OpenAPI Explorer, go to the ListResourceShares debugging page.

    In the Parameters panel, set the endpoint (such as US East 1 (Virginia)) and the required parameter ResourceOwner. Click the CLI Example tab to view the generated command, such as aliyun resourcesharing ListResourceShares --region us-east-1. Click Run or Copy to run or copy the command.

  2. In the Parameter Configuration panel, set the request parameters and click CLI Example to view the generated command.

  3. Copy the CLI command or run it in Cloud Shell:

    • Click Run image to open Cloud Shell and run the command.

    • Click Copy image to copy the command to your clipboard for local execution.

    Note
    • If you run the command locally, verify the parameter format. Parameter formats.

    • OpenAPI Explorer adds --region to the generated command by default, overriding your credential profile region. Remove or keep this option as needed.

Step 4: Call a Resource Sharing API operation

For a list of Resource Sharing API operations that you can call by using Alibaba Cloud CLI, see the API reference.

The following example calls Resource Sharing ListResourceShares to query active resource shares.

  1. Run the following command.

    aliyun resourcesharing ListResourceShares --ResourceOwner Self --ResourceShareStatus Active
  2. Expected output:

    {
      "NextToken": "TGlzdFJlc291cm****",
      "RequestId": "2F23CFB6-A721-4E90-AC1E-0E30FA8B45DA",
      "ResourceShares": [
        {
          "AllowExternalTargets": false,
          "CreateTime": "2020-12-03T02:20:31.292Z",
          "ResourceGroupId": "rg-aekz5nlvlak****",
          "ResourceShareId": "rs-PqysnzIj****",
          "ResourceShareName": "test",
          "ResourceShareOwner": "151266687691****",
          "ResourceShareStatus": "Active",
          "Tags": [
            {
              "Key": "k1",
              "Value": "v1"
            }
          ],
          "UpdateTime": "2020-12-03T08:01:43.638Z"
        }
      ]
    }
    Note
    • If a Resource Sharing API call returns an error, check the error code against your request parameters.

    • Use the request ID or SDK error message with OpenAPI Troubleshoot to diagnose the issue.