This topic provides an example on how to call an operation to query the region in which an asset assigned a public IP address resides.
View API documentation
To query the region in which an asset assigned a public IP address resides, call the DescribeIpLocationService operation. For more information, see List of operations by function. For more information about the data and permissions that are required to call this operation, see API documentation.
Create a RAM user and grant permissions to the RAM user
Identities
You can call this operation by using an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role. For information about the differences between the identities, see Identity, credential, and authorization. In this topic, a RAM user is used as an example.
You can log on to the RAM console, create a RAM user and grant only the permissions to call operations to the RAM user, and then record the AccessKey pair. For more information, see Create a RAM user.
Authorization
Go to the Users page of the RAM console. Find the RAM user that you want to manage and click Add Permissions in the Actions column.
In the Policy section, enter the keyword
Yundunddos
and select the AliyunYundunDDosFullAccess policy.NoteAnti-DDoS Basic provides the following system policies:
AliyunYundunAntiDDoSFullAccess: the permission to manage Anti-DDoS Basic.
AliyunYundunAntiDDoSReadOnlyAccess: the read-only permission to access Anti-DDoS Basic.
Click Grant permissions to complete the authorization.
Credentials
By default, an AccessKey pair is generated when you create a RAM user. You can also go to the details page of the RAM user. On the Authentication tab, click Create AccessKey to create an AccessKey pair. 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 Python 3.
Check the version of Python.
Linux and macOS
Open the terminal and run the
python --version
command.Windows
In the Python installation directory, double-click python.exe.
Start the Command Prompt.
Press Win+R to open the Run dialog box, enter python, and then click OK.
Configure environment variables
In this example, environment variables are configured to manage the AccessKey pair and prevent security risks that are caused by hard-coding the AccessKey pair into your business code. The method that is used to configure environment variables varies based on the operating system. For more information, see Configure environment variables in Linux, macOS, and Windows.
Install dependencies
pip install alibabacloud_credentials
pip install alibabacloud_antiddos_public20170518==1.0.2
pip install alibabacloud_tea_console
Download the sample code
Call the DescribeIpLocationService operation in OpenAPI Explorer. For more information, see DescribeIpLocationService.
Set the InternetIp parameter to 47.110.XX.XX and click Initiate Call.
Click the SDK Sample Code tab. Then, go to the Languages section and click Python.
The system provides the sample code of the API call based on Anti-DDoS Basic SDK for Python.
Click Download Project to download the sample code package.
Decompress the sample code package on your computer and access the alibabacloud_sample directory.
Run sample code
Run the following command:
python sample.py
The following output is returned:
{
"Instance":{
"InstanceId":"eip-bp1bxkujsn1kwo4la****",
"InstanceType":"eip",
"InternetIp":"47.110.XX.XX",
"Region":"cn-hangzhou"
},
"RequestId":"377E4E81-C897-5988-9E61-E51A2262E5C1"
}