This topic uses Python as an example to describe how to use OpenAPI Explorer to create an Anycast elastic IP address (Anycast EIP).
Step 1: View the API references
The List of operations by function topic shows that you can call the AllocateAnycastEipAddress operation to create an Anycast EIP. For more information about the data and permissions that are required to call this operation, see the API documentation.
Step 2: Create a RAM user and grant permissions to the RAM user
An Alibaba Cloud account has access permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call specific API operations or perform routine O&M.
You can call the operation by using an Alibaba Cloud account, a RAM user, or a RAM role. For more information about their differences, see Identity.
In this example, a RAM user is used to call the operation.
Create a RAM user.
Log on to the RAM console.
In the left-side navigation pane, choose
.On the Users page, click Create User.
On the Create User page, specify the Logon Name and Display Name parameters, and set the Access Mode parameter to Console Access.
Click OK.
After you create a RAM user, record the logon name and password of the RAM user. When you call API operations, you must use the RAM user to log on to OpenAPI Explorer.
Grant permissions to the RAM user.
Access the RAM user list.
On the Users page, find the RAM user and click Add Permissions in the Actions column.
Enter
AliyunAnycastEIP
in the search box and select AliyunAnycastEIPFullAccess.The following section describes the permissions on Anycast EIP. For more information about how to create custom permissions, see Authorization.
AliyunAnycastEIPReadOnlyAccess: read-only access to Anycast EIPs.
AliyunAnycastEIPFullAccess: the permission to manage Anycast EIPs.
Click Grant permissions.
Go to the details page of the RAM user. On the Authentication tab, click Create AccessKey.
For more information, see Create an AccessKey pair.
ImportantThe AccessKey secret is displayed only during creation. You cannot view the AccessKey secret after you create it. Download the key information as a CSV file and keep it confidential.
Step 3: Prepare the environment
Download and install Python.
For more information, see Install Python.
Build a Python development environment.
In this example, PyCharm is installed on Windows. For more information, see Build a Python development environment on Windows.
Configure environment variables.
Before you call the operation, you need to configure environment variables. This way, access credentials can be read from the environment variables. For more information about how to configure environment variables in Linux, macOS, and Windows, see Configure environment variables in Linux, macOS, and Windows.
ImportantAfter you configure the environment variables, restart your development tools or services, such as the integrated development environment (IDE). This ensures that the new settings take effect as expected.
Install environment dependencies.
Run the following commands on your device to install the SDK package and environment dependencies for Anycast EIP:
pip install alibabacloud_eipanycast20200309==1.1.2 pip install alibabacloud_tea_console
Step 4: Download the sample code
Log on to the API Debugging page of OpenAPI Explorer as a RAM user.
Select the Anycast EIP service.
In the left-side navigation pane, click AllocateAnycastEipAddress. By default, Region is set to China (Hangzhou). Set ServiceLocation to international.
Click Initiate Call.
In the Call Result section, you can view the results including Request Header and Response Header. A status code of 200 indicates that the call is successful.
Obtain the sample code of the SDK.
OpenAPI Explorer provides SDKs for multiple programming languages, such as Java, Go, Python, Node.js, TypeScript, PHP, and C++. You can integrate SDKs into your applications to directly call API operations. SDKs encapsulate various information, including the data signing logic, timeout mechanism, and retry mechanism. SDKs return structured response objects based on specifications to facilitate development.
The sample code of the SDK for Python is used as an example. You can obtain the code for other programming languages in the same way.
On the SDK Sample Code tab, select an SDK version and language. We recommend that you select V2.0. For information about the differences between V2.0 and V1.0, see Alibaba Cloud SDK V1.0 and V2.0.
Click Download Project to download the complete SDK project. Decompress the project after the project is downloaded.
NoteIn the upper-right corner of the code editor, you can click the icon to copy the SDK sample code.
You can click SDK installation information to obtain basic SDK information such as the SDK package name, SDK package version, SDK package management platform, and SDK installation command for integration and development.
Step 5: Run the SDK sample code
Open PyCharm, click
, select the decompressed project file, click OK in the Creating Virtual Environment window, and wait for the Python virtual environment to be created and dependencies to be downloaded.Run the sample code.
Double-click sample.py in the file directory alibabacloud_sample on the left side of the PyCharm window, and then click the Run button at the top to view the results.
If
"statusCode":200
is returned, the call is successful.