Use OpenAPI examples
This topic describes how to use Cloud Firewall through OpenAPI.
OpenAPI documentation
The API overview lists the supported API operations. This topic uses the Query information about assets protected by Cloud Firewall API operation as an example to demonstrate how to use the SDK sample code.
RAM user creation and authorization
Identity
This example uses a RAM user to call the API operation. For more information about the differences between these identities, see Identities, credentials, and authorization.
Log on to the RAM console, create a RAM user with programmatic access only, and record the AccessKey. For more information, see Create a RAM user.
Authorization
Go to the Users page. Find the RAM user and click Add Permissions in the Actions column.
In the permission policy section, search for CloudFirewall and select the AliyunYundunCloudFirewallFullAccess policy.
NoteCloud Firewall provides the following system permission policies:
AliyunYundunCloudFirewallFullAccess: Grants full management permissions on Cloud Firewall.
AliyunYundunCloudFirewallReadOnlyAccess: Grants read-only permissions on Cloud Firewall.
To learn how to create a custom permission policy, see Authorization information.
Click OK to complete the authorization.
Credential
An AccessKey is generated by default when you create a RAM user. You can also go to the details page of the RAM user, and on the Authentication tab, click Create AccessKey. For more information, see Create an AccessKey.
Call an API
This topic uses Python to demonstrate how to call an API operation.
Prepare a Python environment
Download and install Python.
For the download address of Python 3, see Python 3.
Check the Python version.
On Linux and macOS
Open your terminal and run
python --version.On Windows
In the Python installation directory, double-click python.exe.
Open Command Prompt.
Press Win+R to open the Run dialog box, enter python, and then click OK.
Configure environment variables
To learn how to configure environment variables, see Configure environment variables on 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, open the debugging URL of the Query information about assets protected by Cloud Firewall API operation.
On the Parameters tab, enter values for the required parameters CurrentPage and PageSize, and then click Initiate Call.
On the SDK Sample Code tab, click the Python tab to obtain the Python SDK sample code.
To download the sample code package, click Download Project.
Decompress the sample code package and navigate to the alibabacloud_sample directory.
Run code
Run the following command:
python sample.pyThe command returns the following output:
{
"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
}
}