This example calls the MaxCompute ListProjects API to list MaxCompute projects, demonstrating how to call MaxCompute OpenAPI.
Overview
Alibaba Cloud Command Line Interface (CLI) is a command-line tool built on OpenAPI for automating MaxCompute. What is Alibaba Cloud CLI?.
Step 1: Install Alibaba Cloud CLI
Install Alibaba Cloud CLI for your operating system:
-
Windows: Install the CLI on Windows.
-
Linux: Install or update the CLI.
-
macOS: Install the CLI on macOS.
In Cloud Shell, Alibaba Cloud CLI is pre-installed with automatic credential configuration. Debug commands directly in Cloud Shell. What is Cloud Shell?.
Step 2: Configure Alibaba Cloud CLI
An Alibaba Cloud account (root account) has full permissions for all OpenAPI operations, posing a high security risk. We recommend that you create a RAM user, grant permissions based on the principle of least privilege, and use the RAM user for OpenAPI operations. For MaxCompute, see Identity-based policies.
Configure credentials and a region ID before using Alibaba Cloud CLI. Multiple credential types are supported. Configure and manage credentials. You can use the AccessKey of a RAM user to configure AK-type credentials:
-
Grant the RAM user the
AliyunMaxComputeReadOnlyAccesspermission for read-only access to MaxCompute. Manage RAM user permissions. -
Obtain a region ID. Alibaba Cloud CLI calls OpenAPI from the specified region. For MaxCompute regions, see Endpoints.
NoteThe
--regionoption overrides the region in your credential configuration and environment variables. Command-line options. -
Configure AK-type credentials using the RAM user's AccessKey and name the profile
AkProfile. Configure and manage credentials.
Step 3: Generate a sample CLI command
-
In the OpenAPI portal, go to the ListProjects debugging page.
On the left panel, select a region from the Service Address drop-down list (for example, China (Hangzhou)) and enter request parameters such as
tenantId,region,quotaNickName, andquotaName. Click the CLI Example tab on the right to view the generated command. -
In the Parameter Configuration section, enter request parameters and click the CLI Example tab to view the generated CLI command.
-
Copy the CLI command or run it in Cloud Shell:
-
Click the Run Command button
to open Cloud Shell and quickly debug the command. -
Click the Copy button
to copy the CLI command to the clipboard. You can then paste it into a local shell tool to run it or edit it for an automation script.
NoteWhen pasting the command into a local shell, ensure the parameter format matches the requirements in Understand command parameters.
The generated command includes the
--regionoption by default, which overrides the region in your credential configuration and environment variables. Remove or keep this option as needed. -
Step 4: CallMaxCompute OpenAPI
Example 1: List available OpenAPI operations
Use the --help option to list MaxCompute OpenAPI operations supported by Alibaba Cloud CLI. API overview.
-
Run the following command.
aliyun maxcompute --help -
Output:
shell@Alicloud:~$ aliyun maxcompute --help Alibaba Cloud CLI, Version 3.0.234 Usage 1: aliyun maxcompute [GET|PUT|POST|DELETE] <PathPattern> --body "..." Usage 2 (For API with NO PARAMS in PathPattern only.): aliyun maxcompute <ApiName> --parameter1 value1 --parameter2 value2 ... --body "..." Product: MaxCompute () Version: 2022-01-04 Available Api List: CreatePackage : POST /api/v1/projects/[projectName]/packages CreateProject : POST /api/v1/projects CreateQuotaPlan : POST /api/v1/quotas/[nickname]/plans CreateRole : POST /api/v1/projects/[projectName]/roles DeleteQuotaPlan : DELETE /api/v1/quotas/[nickname]/plans/[planName] GetJobResourceUsage : GET /api/v1/jobs/resourceUsage GetPackage : GET /api/v1/projects/[projectName]/packages/[packageName]
Example 2: List projects
Call the MaxCompute ListProjects API operation to filter and retrieve a MaxCompute project list. List projects.
-
Run the command.
aliyun maxcompute GET /api/v1/projects --tenantId '5495****3697' --quotaName 'aliyun_5495***3697' --header "Content-Type=application/json;" -
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 a MaxCompute API call returns an error, verify your request parameters against the returned error code.
Record the RequestID or SDK error message and use the Alibaba Cloud OpenAPI Diagnostics Platform for self-service diagnostics.