Alibaba Cloud SDK V2.0 simplifies development by encapsulating API calls to create, query, update, and delete ESA resources such as DNS records and certificates.
SDK samples
|
Language |
GitHub repository |
|
Java |
|
|
Go |
|
|
Python |
|
|
PHP |
|
|
.NET |
|
|
Node.js |
https://github.com/aliyun/alibabacloud-typescript-sdk-samples/ |
Usage example
The following Python example creates, updates, and deletes DNS record resources.
Notes
-
Version requirements: Python 3 or later.
-
Costs: Running this sample code operates on live resources and may incur costs.
-
Dependencies:
-
A record depends on a website. Create a website before creating a record.
-
A website depends on a rate plan. Purchase a rate plan before creating a website.
-
-
Asynchronous operations: Purchasing a rate plan, creating a website, and creating, updating, or deleting a record are all asynchronous. Wait for each operation to reach the expected status before you proceed.
Workflow
-
Initialize the client: Configure your credentials as described in Manage access credentials. Then, create a client instance.
-
Purchase a rate plan: Call PurchaseRatePlan to purchase a rate plan and wait for the status to become
running. When you call this operation, you must specify thePlanNameparameter. For the Entrance plan, setPlanNametoentranceplan. You can call theDescribeRatePlanPriceoperation to query available plans and obtain the validPlanNamevalues for each plan. -
Create a website: After you purchase the rate plan, call CreateSite to create a website and wait for the status to become
pending. -
Create a DNS record: After the website is created, call CreateRecord to create a CNAME DNS record. This operation retries automatically when the service is busy. When you call this operation, take note of the following parameters:
-
RecordName(required): The fully qualified domain name (FQDN) of the record, such aswww.example.com. In the ESA console, the website domain suffix is appended automatically. However, when you use the SDK, you must specify the complete domain name. Set the value to@to represent the root domain. -
Data(required): An object that contains the record data. For a CNAME record, setData.Valueto the target domain name. Omitting this parameter causes aMissingDataerror. -
SourceType(optional, applies to CNAME records): The origin type. Valid values:Domain(default),OSS,S3,LB, andOP. If you set this parameter toOSSorS3, you must also specifyAuthConf. -
BizName(optional): The business scenario when proxy acceleration is enabled. Valid values:web,file,image_video,api, andai.
-
-
Update the DNS record: Call UpdateRecord to update the DNS record. This operation retries automatically when the service is busy. The
Dataparameter is required. Omitting it causes aMissingDataerror. -
Delete the DNS record: Call DeleteRecord to delete the DNS record and wait for the deletion to complete. This operation retries automatically when the service is busy.