This topic describes how to use Alibaba Cloud Command Line Interface (CLI) to call the MaxCompute OpenAPI, demonstrated through the example of invoking the ListProjects
API to fetch a list of MaxCompute projects.
Background information
Alibaba Cloud CLI is a command line tool based on OpenAPI. It allows for the automation of management and maintenance tasks for MaxCompute. For more information, see What is Alibaba Cloud CLI?
Step 1: Install Alibaba Cloud CLI
First, choose the appropriate installation package for your operating system.
Windows: Install Alibaba Cloud CLI on Windows
Cloud Shell is pre-installed with Alibaba Cloud CLI and automatically configures your identity credentials, simplifying the setup process. You can test Alibaba Cloud CLI commands in Cloud Shell. For more information, see What is Cloud Shell?
Step 2: Configure Alibaba Cloud CLI
For security reasons, we recommend that you create a Resource Access Management (RAM) user and assign permissions based on the principle of least privilege when accessing OpenAPI. For more information about the policies supported by MaxCompute, see Identity-based policies.
Alibaba Cloud CLI supports various credential types. For more information, see Credential types. You can use the AccessKey of a RAM user to configure its identity credentials. Follow these steps to set up AK-type credentials:
Create a RAM user and an AccessKey pair to configure the identity credentials. For more information, see Create a RAM user and Create an AccessKey pair.
Grant the RAM user permissions. In this example, assign the RAM user read-only access to MaxCompute by using the
AliyunMaxComputeReadOnlyAccess
policy. For more information, see Grant permissions to a RAM user.Get the region ID for your operations. Alibaba Cloud CLI uses the specified region ID to initiate API calls. For available regions for MaxCompute, see Endpoints.
NoteWhen using Alibaba Cloud CLI, you can use the
--region
option and its parameterregion
to specify a region. After you specify a valid region, Alibaba Cloud CLI ignores the region in the default identity credential and environment variable configurations and uses the region that you specify to run commands. For more information, see Command line options for API calls.Configure AK-type credentials by using the AccessKey of the RAM user and name the configuration file
AkProfile
. For more information, see Configuration examples.
Step 3: Generate a sample CLI command
Visit the or ListProjects debugging address.
Input the request parameters in the Parameters section and click the CLI Example tab to see the generated CLI command.
Copy the CLI command or execute it quickly in Cloud Shell:
Click the Run Command button to open Cloud Shell and complete command debugging.
Click the Copy button to copy the CLI command to your clipboard. You can then paste it into your local shell to run or modify it for automated command line scripts.
NoteWhen pasting the CLI command into your local shell for testing, ensure that the parameter formats are correct. For details on parameter formats in Alibaba Cloud CLI commands, see Parameter formats.
The OpenAPI portal automatically includes the
--region
option in the generated command. When executing the command locally, Alibaba Cloud CLI prioritizes the specified region over the default identity credential configuration and environment variable settings. You may choose to keep or remove this option as needed.
Step 4: Call MaxCompute OpenAPI
Example 1: Obtain the OpenAPI list
The following example demonstrates how to use the --help
option to retrieve a list of MaxCompute OpenAPI operations that are supported by Alibaba Cloud CLI. For more information, see List of operations by function.
Execute the following command:
aliyun maxcompute --help
Expected output:
Example 2: Obtain the project list
The following example demonstrates how to use Alibaba Cloud CLI to call the MaxCompute ListProjects
API to filter and retrieve a list of MaxCompute projects based on input parameters. For the details of the API, see ListProjects.
Execute the following command:
aliyun maxcompute GET /api/v1/projects --tenantId '5495****3697' --quotaName 'aliyun_5495***3697' --header "Content-Type=application/json;"
Expected output:
{ "requestId": "0b16399216671970335563173e2340", "data": { "projects": [ { "name": "odps_project", "owner": "ALIYUN$odps****@aliyunid.com\n", "type": "managed", "comment": "BI_Analysis", "defaultQuota": "os_PayAsYouGoQuota\n", "status": "AVAILABLE", "costStorage": "16489027", "regionId": "cn-beijing", "createdTime": 1704380838000, "properties": { "timezone": "Asia/Shanghai\n", "retentionDays": 1, "allowFullScan": false, "typeSystem": "2", "enableDecimal2": true, "sqlMeteringMax": "1500", "tableLifecycle": { "type": "optional", "value": "37231\n" }, "encryption": { "enable": true, "algorithm": "AES256", "key": "dafault" }, "tunnelQuota": "Default", "enableTunnelQuotaRoute": true, "externalProjectProperties": { "isExternalCatalogBound": "true" } }, "securityProperties": { "usingAcl": true, "usingPolicy": true, "objectCreatorHasAccessPermission": true, "objectCreatorHasGrantPermission": true, "labelSecurity": false, "enableDownloadPrivilege": false, "projectProtection": { "protected": true, "exceptionPolicy": "{\n \"Version\": \"1\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Principal\": \"\",\n \"Action\": [\n \"odps:[, , ...]\"\n ],\n \"Resource\": \"acs:odps:*:\",\n \"Condition\": {\n \"StringEquals\": {\n \"odps:TaskType\": [\n \"\"\n ]\n }\n }\n }\n ]\n}" } }, "ipWhiteList": { "ipList": "10.88.111.3", "vpcIpList": "10.88.111.3" }, "saleTag": { "resourceId": "b7afb7d1-****-****-****-c393669c307b\n", "resourceType": "PayAsYouGo\n" }, "threeTierModel": true } ], "marker": "cHlvZHBzX3VkZl8xMDExNV8xNDU3NDI4NDkzKg==", "maxItem": 10, "NextToken": "AAAAAV3MpHK1AP0pfERHZN5pu6kvikyUl3ChyRxN+qLPvtOb" } }
NoteIf an error occurs after calling the MaxCompute OpenAPI, verify the request parameters and their values against the returned error code.
You can record the RequestID from the call or the error message from the SDK. For self-service diagnostics, use the or Alibaba Cloud OpenAPI Diagnostics Platform.