This topic describes how to call an API operation of Cloud Firewall.
View API documentation
You can view the supported API operations in List of operations by function. In this topic, the DescribeAssetList operation is used as an example to show how to call an API operation by using an Alibaba Cloud SDK. For more information, see DescribeAssetList - Queries the assets that are protected by Cloud Firewall.
Create a RAM user and grant permissions to the RAM user
Identity
You can call an operation by using an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role. For more information about the differences among the identities, see Identity, credential, and authorization. In this topic, a RAM user is used as an example.
Log on to the RAM console, create a RAM user that is authorized only to call API operations, and then record the AccessKey pair of the RAM user. For more information, see Create a RAM user.
Authorization
Go to the Users page of the RAM console, find the RAM user, and click Add Permissions in the Actions column.
In the Policy section, enter CloudFirewall in the search box to search for and select the AliyunYundunCloudFirewallFullAccess policy.
NoteThe following list describes the system policies of Cloud Firewall:
AliyunYundunCloudFirewallFullAccess: management permissions on Cloud Firewall.
AliyunYundunCloudFirewallReadOnlyAccess: read-only permissions on Cloud Firewall.
For more information about how to create custom policies, see RAM authorization.
Click Grant permissions.
Credential
By default, an AccessKey pair is generated when you create a RAM user. You can directly use the AccessKey pair. You can also perform the following operations to create an AccessKey pair: Go to the details page of a RAM user. On the Authentication tab, click Create AccessKey. For more information, see Create an AccessKey pair.
Call the operation
The following example shows how to call the operation in Python.
Prepare a Python environment
Download and install Python.
For more information about how to download Python 3, visit the official website of Python.
Check the version of Python.
Linux or macOS
Open the terminal and run the
python --versioncommand.Windows
In the Python installation directory, double-click python.exe.
Open the Command Prompt.
Press the Win+R keys to open the Run dialog box, enter python, and then click OK.
Configure environment variables
For more information about how to configure environment variables, see Configure environment variables in Linux, macOS, and Windows.
Install dependencies
pip install alibabacloud_credentials
pip install alibabacloud_cloudfw20171207==1.3.2
pip install alibabacloud_tea_consoleDownload the sample code
In OpenAPI Explorer, access the URL of the DescribeAssetList operation.
On the Parameters tab, specify the required parameters CurrentPage and PageSize, and click Initiate Call.
On the SDK Sample Code tab, click the Python tab to obtain the Python sample code of the operation.
Click Download Project to download the sample code package.
Decompress the sample code package on your computer and go to the alibabacloud_sample directory.
Run the sample code
Run the following command:
python sample.pyThe following command output is displayed:
{
"headers": {
"date": "Thu, 10 Aug 2023 10:18:48 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "1194",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"vary": "Accept-Encoding",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "B49120FC-5A22-5500-A005-060F487E****",
"x-acs-trace-id": "e04deb393afe188190485401aa41****",
"etag": "1SZicxaXw+FjDwnyteba****"
},
"statusCode": 200,
"body": {
"Assets": [{
"AliUid": 163710033944****,
"BindInstanceId": "i-bp14vt99zpj899eq****",
"BindInstanceName": "launch-****-20210409",
"CreateTimeStamp": "2023-07-05 15:05:01",
"InternetAddress": "118.31.XX.XX",
"IntranetAddress": "192.168.XX.XX",
"MemberUid": 163710033944****,
"Name": "launch-****-20210409",
"NewResourceTag": "",
"Note": "",
"ProtectStatus": "closed",
"RegionID": "cn-hangzhou",
"RegionStatus": "enable",
"ResourceInstanceId": "i-bp14vt99zpj899eq****",
"ResourceType": "EcsPublicIP",
"RiskLevel": "",
"SgStatus": "block",
"SgStatusTime": 1691350656,
"SyncStatus": "enable",
"Type": "ecs"
}, {
"AliUid": 163710033944****,
"BindInstanceId": "i-bp1ic3k18jrurbxd****",
"BindInstanceName": "launch-****-20230712",
"CreateTimeStamp": "2023-07-12 17:49:46",
"InternetAddress": "47.111.XX.XX",
"IntranetAddress": "10.0.XX.XX",
"MemberUid": 163710033944****,
"Name": "launch-****-20230712",
"NewResourceTag": "",
"Note": "",
"ProtectStatus": "closed",
"RegionID": "cn-hangzhou",
"RegionStatus": "enable",
"ResourceInstanceId": "i-bp1ic3k18jrurbxd****",
"ResourceType": "EcsPublicIP",
"RiskLevel": "",
"SgStatus": "block",
"SgStatusTime": 1691350656,
"SyncStatus": "enable",
"Type": "ecs"
}],
"RequestId": "B49120FC-5A22-5500-A005-060F487EF211",
"TotalCount": 16
}
}