This guide walks you through calling the DTS (Data Transmission Service) WhiteIpList API using the Alibaba Cloud SDK for Python.
Prerequisites
Before you begin, ensure that you have:
-
An Alibaba Cloud account
-
Python 3 installed (
python --versionto check) -
The pip package manager
Step 1: Read the API documentation
Before calling an API operation, read its documentation to understand the request parameters and expected response. See List of operations by function.
Step 2: Create a RAM user and grant permissions
Skip this step if you already have a RAM user with DTS permissions.
Create a RAM user:
-
Log on to the RAM console and go to the Users page. Click Create User.
-
Set Logon Name to
dts-openapi-operatorand set Access Mode to Using permanent AccessKey to access. -
Click OK and save the AccessKey ID and AccessKey secret.
Grant DTS permissions:
-
On the Users page, find the RAM user and click Add Permissions in the Actions column.
-
In the panel, enter
Aliyundtsin the search box and select AliyunDTSFullAccess. -
Click Grant permissions.
AliyunDTSFullAccess grants read and write permissions on DTS — the RAM user can purchase, configure, and manage DTS instances. AliyunDTSReadOnlyAccess grants read-only access to view task details and configurations, but does not allow changes. For custom permission policies, see Use a custom policy to authorize a RAM user to manage DTS instances.
Step 3: Configure environment variables
Store your credentials as environment variables rather than hardcoding them.
Linux or macOS:
export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
Windows:
Create a file to set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables, then restart the system.
Replace <access_key_id> and <access_key_secret> with the values you saved in Step 2.
Step 4: Install dependencies
Run the following commands in your terminal:
pip install alibabacloud_credentials
pip install alibabacloud_dts20200101
pip install alibabacloud_tea_console
Step 5: Download the sample code
-
Go to the WhiteIpList API page.
-
On the Parameters tab, configure the request parameters. For this example, set Type to
vpcand Region tocn-hangzhou. -
On the SDK Sample Code tab, select Python and click Download Project.
-
Decompress the package and navigate to the
alibabacloud_sampledirectory.
Step 6: Run the code
python sample.py
A successful response looks like:
{
"headers": {
"date": "Wed, 26 Jul 2023 01:38:10 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "2349",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"vary": "Accept-Encoding",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "F67A05B4-639B-5A3E-800F-2015E31D****",
"x-acs-trace-id": "cd5216b8e3d13a155510760d6b7f****",
"etag": "2iMUqZd0YJhWwB0iy0qP****"
},
"statusCode": 200,
"body": {
"HttpStatusCode": 200,
"IpList": "100.104.XX.XX/XX,100.104.XX.XX/XX,100.104.XX.XX/XX,****",
"RequestId": "F67A05B4-639B-5A3E-800F-2015E31D****",
"Success": true
}
}
Success: true and statusCode: 200 confirm the call succeeded. The IpList field contains the IP allowlist for the VPC in the specified region.
What's next
-
Explore other DTS API operations: List of operations by function
-
Use SDKs for other programming languages: Data Transmission SDK