Manage ESA resources using an SDK

更新时间:
复制 MD 格式

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

https://github.com/aliyun/alibabacloud-java-sdk-samples/

Go

https://github.com/aliyun/alibabacloud-go-sdk-samples/

Python

https://github.com/aliyun/alibabacloud-python-sdk-samples/

PHP

https://github.com/aliyun/alibabacloud-php-sdk-samples/

.NET

https://github.com/aliyun/alibabacloud-net-sdk-samples/

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

  1. Initialize the client: Configure your credentials as described in Manage access credentials. Then, create a client instance.

  2. 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 the PlanName parameter. For the Entrance plan, set PlanName to entranceplan. You can call the DescribeRatePlanPrice operation to query available plans and obtain the valid PlanName values for each plan.

  3. Create a website: After you purchase the rate plan, call CreateSite to create a website and wait for the status to become pending.

  4. 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 as www.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, set Data.Value to the target domain name. Omitting this parameter causes a MissingData error.

    • SourceType (optional, applies to CNAME records): The origin type. Valid values: Domain (default), OSS, S3, LB, and OP. If you set this parameter to OSS or S3, you must also specify AuthConf.

    • BizName (optional): The business scenario when proxy acceleration is enabled. Valid values: web, file, image_video, api, and ai.

  5. Update the DNS record: Call UpdateRecord to update the DNS record. This operation retries automatically when the service is busy. The Data parameter is required. Omitting it causes a MissingData error.

  6. 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.