This topic demonstrates how to call the Cloud Control API online through OpenAPI Explorer to manage cloud resources. Using Virtual Private Cloud (VPC) as an example, it walks through the operations for creating, querying, updating, and deleting a VPC resource. It also describes how to query the task status when the Cloud Control API handles tasks asynchronously.
Prerequisites
To ensure smooth operations, complete the following preparations:
-
Because an Alibaba Cloud account (root account) has all permissions on resources, a leak poses a significant risk. We recommend that you use a RAM user. For more information, see Create a RAM user.
-
Before you call the Cloud Control API, first grant the RAM user the permissions to operate the corresponding resources, and then grant the AliyunCloudControlAPIFullAccess policy to ensure that it has all the permissions required to manage the Cloud Control API. For more information, see Manage RAM user permissions.
Call the Cloud Control API online through OpenAPI Explorer
This tutorial uses Virtual Private Cloud (VPC) as an example. The product code of VPC is VPC, and the resource type code is also VPC. With the product code and the resource type code, you can query the details of the resource type. By calling the Cloud Control API online, you can create, get, update, list, and delete VPC resources.
Create a VPC resource
This operation is used to create a VPC resource.
-
As a RAM user, log on to OpenAPI Explorer. After you go to the VPC resource creation page, select regionId, and set the body resource property parameters. Then click Initiate Call. In the sample code section on the right, you can select a programming language, and the system automatically generates code for your reference.
After you initiate the call, view the call result.
If the call returns an error, refer to Diagnose for the log information, the API documentation, or Public error codes to analyze and resolve the issue. You can also Contact us.
If the call succeeds, record the resource ID (resourceId) in the response. A status code of 200 indicates a synchronous operation, which means the resource creation task is complete. A status code of 202 indicates an asynchronous operation, and you must further query the task status based on the returned taskId.
NoteSynchronous operations and asynchronous operations are two modes in which a program handles task execution. The difference is that a synchronous operation returns only after the task is complete, whereas an asynchronous operation returns without waiting for the task to complete.
In this example, the call result returns a status code of 202, which indicates an asynchronous operation. You must query the task status by using the taskId. Record the taskId and click Query task to go to the task query page.
Enter taskId, and click Initiate Call. View the call result: the call succeeds, the task status is Succeeded, and the VPC resource is created.
Result verification: view the created VPC in the VPC console.
Get a VPC resource
This operation is used to get the details of a VPC resource. On the VPC resource get page, enter the resourceId, select regionId, and click Initiate Call. View the call result: the call succeeds and the resource details are returned.
Update a VPC resource
This operation is used to update the information of a VPC resource. On the VPC resource update page, enter the resourceId, select regionId, enter the parameter values that you want to update, and click Initiate Call. View the call result. To verify the update, view the resource information in the VPC console or by calling the Cloud Control API.
List VPC resources
This operation is used to list the information of all VPC resources. On the VPC resource list page, select regionId, and click Initiate Call. View the call result to see the resource information.
The sample parameters are as follows:
requestPath:
/api/v1/providers/Aliyun/products/VPC/resources/VPCregionId:
cn-beijing
Delete a VPC resource
This operation is used to delete a specified VPC resource.
The delete operation is irreversible. Proceed with caution. Before you delete a VPC, we recommend that you fully verify the deletion process in a test environment, and then perform the operation on production resources only after you confirm that everything is correct.
On the VPC resource delete page, enter the resourceId, select regionId, and click Initiate Call, and then view the call result.
The call succeeds and returns a status code of 202, which indicates that this call is an asynchronous operation.
On the task query page, enter taskId, and click Initiate Call. View the call result: the task status is Succeeded, which means the VPC resource is deleted.
Sample code
Code repository: https://github.com/aliyun/cloud-control-api-demo
This repository provides code samples for the Cloud Control API to help you query resource metadata and manage cloud resources.