Use an OpenAPI SDK example
This topic provides a complete Python example that demonstrates how to call an OpenAPI operation to query a list of Database File System (DBFS) instances.
View the OpenAPI document
Read the API overview. The ListDbfs operation is used to query the list of DBFS instances. Review the document to understand the data and permissions required to call this operation.
Create a RAM user and grant permissions
If you have already created a Resource Access Management (RAM) user and granted permissions, you can skip this step.
Create a RAM user.
Go to the RAM User List page and click Create User.
Set the logon name to dbfs-openapi-operator and Access Mode to OpenAPI Call Access.
Click OK to create the RAM user. Then, save the AccessKey ID and AccessKey secret.
Grant permissions.
Go to the RAM User List page. In the Actions column for the target RAM user, click Add Permissions.
In the text box, search for
AliyunDBFSand select the AliyunDBFSReadOnlyAccess policy.ImportantAliyunDBFSFullAccess grants full operational permissions. You can also select the AliyunDBFSReadOnlyAccess permission, which grants read-only access, or create a custom policy as needed.
Click OK to complete the authorization.
Call the OpenAPI
This topic uses Python as an example to demonstrate how to call the OpenAPI operation. The process is similar for SDKs in other languages. For more information, see Database File System SDK.
Prepare the Python environment
Download and install Python 3. If Python is already installed, run the following command to check its version: python --version.
Configure environment variables
To avoid the security risks of hard-coding an AccessKey into your code, configure environment variables to manage your AccessKey.
Linux and macOS systems
Replace
<access_key_id>and<access_key_secret>with your AccessKey ID and AccessKey secret. Then, run the following commands in your terminal.export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>Windows systems
Create an environment variable file. Add the
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables and set their values to your AccessKey ID and AccessKey secret.Restart the Windows system.
Install dependencies
Run the following commands in your terminal to install the dependencies.
pip install alibabacloud_dbfs20200418==3.2.2
pip3 install alibabacloud_tea_consoleDownload the sample code
The following example shows how to call the ListDbfs API operation. You can select other API operations to call in the OpenAPI Portal.
Go to the ListDbfs debugging page in the OpenAPI Portal.
On the Parameter Settings tab on the left, fill in the required parameters. For this example, set Endpoint to China (Hangzhou).
On the SDK Example tab on the right, select the Python language and click the Download Complete Project button to download the sample code package.
Extract the package locally and navigate to the alibabacloud_sample folder.
Run the code
Run the following command:
python sample.pyThe following example shows a sample response:
{
"headers":{
"date":"Tue, 29 Aug 2023 09:29:26 GMT",
"content-type":"application/json;charset=utf-8",
"content-length":"712",
"connection":"keep-alive",
"keep-alive":"timeout=25",
"access-control-allow-origin":"*",
"access-control-expose-headers":"*",
"x-acs-request-id":"D7C4D965-BB09-5511-98D3-73B20B7C****",
"x-acs-trace-id":"2197b03a4f574d563d235b786123****",
"etag":"7wZSDTchJP7sQjIK0CDu****"
},
"statusCode":200,
"body":{
"DBFSInfo":[
{
"AttachNodeNumber":0,
"Category":"standard",
"CreatedTime":1693299715000,
"DBFSClusterId":"3c6e44c6-ddfe-4acc-a1b9-97e1302d****",
"EbsList":[
{
"EbsId":"d-bp16if0mkkz8cnzi****",
"SizeG":20
}
],
"EcsList":[
],
"EnableRaid":false,
"Encryption":false,
"FsId":"dbfs-rgn6no98snav7cgw6v****",
"FsName":"test",
"InstanceType":"dbfs.medium",
"KMSKeyId":"",
"LastFailed":"",
"PayType":"postpaid",
"PerformanceLevel":"PL1",
"RaidStrip":1,
"RegionId":"cn-hangzhou",
"SizeG":20,
"SnapshotInfo":{
"LinkId":"-",
"PolicyId":"-",
"SnapshotCount":0,
"TotalSize":0
},
"Status":"unattached",
"Tags":[
],
"UsedScene":"MySQL 5.7",
"ZoneId":"cn-hangzhou-i"
}
],
"PageNumber":1,
"PageSize":10,
"RequestId":"D7C4D965-BB09-5511-98D3-73B20B7C****",
"TotalCount":1
}
}