Capability Overview
Directory Structure
aliyun-cdn-skills/
├── SKILL.md
├── reference/ # API 定义(YML),含入参与返回值
│ ├── describe_user_domains.yml
│ ├── describe_cdndomain_detail.yml
│ ├── describe_cdndomain_configs.yml
│ ├── describe_domain_cname.yml
│ ├── check_cdndomain_icp.yml
│ ├── describe_verify_content.yml
│ ├── describe_domain_verify_data.yml
│ ├── verify_domain_owner.yml
│ ├── add_cdndomain.yml
│ ├── batch_update_cdndomain.yml
│ ├── batch_set_cdndomain_config.yml
│ ├── refresh_object_caches.yml
│ ├── start_cdndomain.yml
│ └── set_cdndomain_sslcertificate.yml
└── scripts/ # 可执行脚本与依赖清单
├── describe_user_domains.py
├── describe_cdndomain_detail.py
├── describe_cdndomain_configs.py
├── describe_domain_cname.py
├── check_cdndomain_icp.py
├── describe_verify_content.py
├── describe_domain_verify_data.py
├── verify_domain_owner.py
├── add_cdndomain.py
├── batch_update_cdndomain.py
├── batch_set_cdndomain_config.py
├── refresh_object_caches.py
├── start_cdndomain.py
├── set_cdndomain_sslcertificate.py
└── requirements.txt
- reference/: Stores API-related information, including input parameters, return values, etc. (YML), for consulting the contract and field meanings.
- scripts/: Python scripts that can be run directly (for example
python scripts/describe_user_domains.py); you can also read their implementation and write or rewrite new code based on them. - Dependencies:
requirements.txtis located in thescripts/directory; for first-time use, please first runpip install -r aliyun-cdn-skills/scripts/requirements.txtto install dependencies.
This skill provides the followingindependent capabilities, which can be called individually or used in combination according to actual needs:
| Capability | API | Type | Purpose | reference | scripts |
|---|---|---|---|---|---|
| Query user domain list | DescribeUserDomains | Read | Paginated query of accelerated domains and their status under the account, with filtering support | describe_user_domains.yml | describe_user_domains.py |
| Query domain details | DescribeCdnDomainDetail | Read | Query the basic configuration of a specified accelerated domain (origin server, CNAME, status, etc.) | describe_cdndomain_detail.yml | describe_cdndomain_detail.py |
| Query domain feature configuration | DescribeCdnDomainConfigs | Read | Query the feature configuration on a domain by feature name or ConfigId | describe_cdndomain_configs.yml | describe_cdndomain_configs.py |
| Detect CNAME | DescribeDomainCname | Read | Detect whether the accelerated domain CNAME resolves to the expected target | describe_domain_cname.yml | describe_domain_cname.py |
| Query ICP filing | CheckCdnDomainICP | Read | Query whether the domain has an ICP filing | check_cdndomain_icp.yml | check_cdndomain_icp.py |
| Query ownership verification content | DescribeVerifyContent | Read | Query the content required for domain ownership verification (single domain) | describe_verify_content.yml | describe_verify_content.py |
| Query domain verification data | DescribeDomainVerifyData | Read | Return the corresponding verification data based on the global resource plan, etc. (single domain) | describe_domain_verify_data.yml | describe_domain_verify_data.py |
| Verify domain ownership | VerifyDomainOwner | Write | Verify domain ownership (single domain) | verify_domain_owner.yml | verify_domain_owner.py |
| Add accelerated domain | AddCdnDomain | Write | Add a new accelerated domain | add_cdndomain.yml | add_cdndomain.py |
| Batch update domains | BatchUpdateCdnDomain | Write | Batch update basic information of accelerated domains | batch_update_cdndomain.yml | batch_update_cdndomain.py |
| Batch set domain configuration | BatchSetCdnDomainConfig | Write | Batch set feature configuration for multiple domains (limits such as the product of the number of domains and the number of feature items are specified in the YML) | batch_set_cdndomain_config.yml | batch_set_cdndomain_config.py |
| Refresh cache | RefreshObjectCaches | Write | Batch refresh URLs/directories so that node caches immediately expire and content is fetched from the origin | refresh_object_caches.yml | refresh_object_caches.py |
| Enable domain | StartCdnDomain | Write | Enable an accelerated domain that is in a disabled state | start_cdndomain.yml | start_cdndomain.py |
| Set HTTPS certificate | SetCdnDomainSSLCertificate | Write | Set the certificate switch and certificate content (upload/CAS, etc.) | set_cdndomain_sslcertificate.yml | set_cdndomain_sslcertificate.py |
Important Notes:
- Each capability corresponds to an independent API,with no fixed call order; they can be combined according to business needs (for example, list first and then get details, or perform an ICP filing check before adding a domain).
- Write operations(add, batch update, batch set configuration, refresh cache, submit ownership verification, enable, certificate, etc.) require the account or RAM user to have the corresponding CDN write permissions; before making changes in the production environment, it is recommended to first verify in the console or on a test domain.RefreshObjectCaches will cause the cache to expire immediately and increase origin fetch traffic, so control batch size and frequency.
Prerequisite checks (must be performed first)
Before executing any call, you must first confirm that AK/SK have been configured.
Check order
1. Check environment variables first
echo "AK_ID: ${ALIBABA_CLOUD_ACCESS_KEY_ID:+已设置}"
echo "AK_SECRET: ${ALIBABA_CLOUD_ACCESS_KEY_SECRET:+已设置}"
2. If not set, check the current working directory's .env file
find . -maxdepth 1 -name ".env" -exec cat {} \;
.env file format:
ALIBABA_CLOUD_ACCESS_KEY_ID=your-access-key-id
ALIBABA_CLOUD_ACCESS_KEY_SECRET=your-access-key-secret
3. Load credentials in Python code
from dotenv import load_dotenv
import os
access_key_id = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID", "").strip()
access_key_secret = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET", "").strip()
if not access_key_id or not access_key_secret:
load_dotenv()
access_key_id = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID", "").strip()
access_key_secret = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET", "").strip()
if not access_key_id or not access_key_secret:
raise RuntimeError("缺少阿里云凭证。请先设置 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET")
If the credential check does not pass, subsequent steps should not continue.
Install dependencies
pip install -r aliyun-cdn-skills/scripts/requirements.txt
or install manually:
pip install alibabacloud_cdn20180510 alibabacloud_credentials alibabacloud_tea_openapi alibabacloud_tea_util python-dotenv
Client initialization (CDN)
Initialize using the credential chain Cdn20180510Client, with endpoint fixed to cdn.aliyuncs.com(consistent with existing scripts):
from alibabacloud_cdn20180510.client import Client as Cdn20180510Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
credential = CredentialClient()
config = open_api_models.Config(credential=credential)
config.endpoint = "cdn.aliyuncs.com"
client = Cdn20180510Client(config)
The request models for each API are located in alibabacloud_cdn20180510.models, and the call pattern is client.<api>_with_options(request, runtime), see the corresponding scripts/*.py。
Pagination (DescribeUserDomains)
reference/describe_user_domains.yml in PageSize takes the value 1~500(default 20),PageNumber is the page number. When you need to fetchall domains, you should loop and increment in code PageNumber, until the returned data is less than one page or the total number of pages is reached.
In the repository, scripts/describe_user_domains.py is a minimal example (pagination parameters not filled in); for production or full synchronization, you need to implement the pagination loop yourself.
Common combinations (not mandatory)
- Operations troubleshooting: DescribeUserDomains → DescribeCdnDomainDetail / DescribeCdnDomainConfigs.
- Onboarding and resolution: DescribeDomainCname verifies the CNAME; DescribeCdnDomainDetail checks the assigned CNAME.
- Before launching a new domain: after verifying CheckCdnDomainICP against business requirements, then AddCdnDomain or make later configuration changes.
- Domain ownership: DescribeVerifyContent / DescribeDomainVerifyData obtains the verification method and data; after completing DNS/file verification according to the console or documentation, then VerifyDomainOwner submit verification (specific parameters and process are subject to the YML and official documentation).
- Batch modify feature items: BatchSetCdnDomainConfig and BatchUpdateCdnDomain have different focus (the former is more about Functions batch configuration on domains); control the number of domains and feature items per request according to YML limits.
- Publishing and caching:RefreshObjectCaches refresh URLs/directories after resource updates; note quotas such as the number of URL domains per task (see YML).
- HTTPS: after checking the certificate status with DescribeCdnDomainDetail, use SetCdnDomainSSLCertificate to update the certificate or toggle it.
Error handling recommendations
401/403: AK/SK is invalid, not configured, or RAM permissions are insufficient.InvalidAccessKeyId: AccessKeyId is incorrect.SignatureDoesNotMatch: AccessKeySecret is incorrect or the signature does not match.- If the exception contains
dataand within it there isRecommend, prioritize troubleshooting according to the diagnostic link.
API descriptions (brief)
The following is for indexing only;request/response fields are subject to the corresponding YML, and example calls are subject to scripts .
DescribeUserDomains
Query the list of accelerated domains under the account, supporting fuzzy domain matching and status filters. See details in reference/describe_user_domains.yml, example:scripts/describe_user_domains.py。
DescribeCdnDomainDetail
Query basic information for a single accelerated domain (origin, CNAME, business type, running status, etc.). See details in reference/describe_cdndomain_detail.yml, example:scripts/describe_cdndomain_detail.py。
DescribeCdnDomainConfigs
Query the features already configured on a domain (e.g. FunctionNames comma-separated). See reference/describe_cdndomain_configs.ymlfor details, example:scripts/describe_cdndomain_configs.py。
DescribeDomainCname
Perform a CNAME resolution check on an accelerated domain (for the maximum number of domains per request, see the YML description). See reference/describe_domain_cname.ymlfor details, example:scripts/describe_domain_cname.py。
CheckCdnDomainICP
Query domain ICP filing related information.Read API, used for compliance verification. See reference/check_cdndomain_icp.ymlfor details, example:scripts/check_cdndomain_icp.py。
DescribeVerifyContent
Query the accelerated domainownership verificationrequired content (single domain).Read API. See reference/describe_verify_content.ymlfor details, example:scripts/describe_verify_content.py。
DescribeDomainVerifyData
Based on the domain and whetherGlobal Resource Planand other conditions are enabled, return the corresponding verification data/content (single domain).Read API. See reference/describe_domain_verify_data.ymlfor details, example:scripts/describe_domain_verify_data.py。
VerifyDomainOwner
Verify domain ownership (single domain). The OpenAPI marks it as a write operation; before calling, DNS/file verification steps usually need to be completed first.Write API. See reference/verify_domain_owner.ymlfor details, example:scripts/verify_domain_owner.py。
AddCdnDomain
Add an accelerated domain.Write API, requires create and configure permissions; there are many parameters (origin server, acceleration region, business type, etc.), so be sure to fill them in according to the YML. See reference/add_cdndomain.ymlfor details, example:scripts/add_cdndomain.py。
BatchUpdateCdnDomain
Batch update basic information for accelerated domains.Write API, before making changes it is recommended to confirm the scope of impact. See reference/batch_update_cdndomain.ymlfor details, example:scripts/batch_update_cdndomain.py。
BatchSetCdnDomainConfig
For multiple accelerated domainsbatch set feature configurations(Functions , etc.).Write API; the number of domains per request, the upper limit of the product with the number of feature items, etc. are subject to the YML. See reference/batch_set_cdndomain_config.ymlfor details, example:scripts/batch_set_cdndomain_config.py。
Private OSS Bucket origin configuration
When the origin server is a private Alibaba Cloud OSS Bucket, the private origin feature must be enabled for CDN to properly fetch resources from the origin:
import json
from alibabacloud_cdn20180510 import models as cdn_20180510_models
# 配置私有 OSS 回源
functions = [{
"functionName": "l2_oss_key",
"functionArgs": [
{
"argName": "private_oss_auth",
"argValue": "on"
}
]
}]
request = cdn_20180510_models.BatchSetCdnDomainConfigRequest(
domain_names="www.example.com",
functions=json.dumps(functions)
)
Key parameter description:
functionName:l2_oss_key- OSS private Bucket origin featureargName:private_oss_auth- Private OSS authentication switchargValue:onEnable private origin,offDisable private origin
RefreshObjectCaches
By URL or directoryrefreshnode cache, invalidating the cache of the corresponding objects and fetching the latest content from the origin; batch supported,Write API. Note origin fetching and quotas (for the number of domains in a single URL, etc., see the YML). See reference/refresh_object_caches.ymlfor details, example:scripts/refresh_object_caches.py。
StartCdnDomain
Enable an accelerated domain in thedisabledstate to Online.Write API, the domain and account status must be normal. See reference/start_cdndomain.ymlfor details, example:scripts/start_cdndomain.py。
SetCdnDomainSSLCertificate
Configure the HTTPS certificate switch (SSLProtocol) and certificate content or CAS certificate reference, etc.Write API; when certificates and private keys are involved, pay attention to confidentiality and permissions. See reference/set_cdndomain_sslcertificate.ymlfor details, example:scripts/set_cdndomain_sslcertificate.py。
Notes
- reference/ The YML in is used to look up API input parameters and return values;scripts/ The scripts in can be run directly to verify the environment and SDK calls.
- If the business scenario differs from the example, after reading the YML and scripts, rewrite or create new code yourself.
- For write-operation APIs, follow the principle of least privilege and configure only the required actions for the RAM user.
Capability extension
This skill can continue to add other CDN OpenAPIs (for example, disabling domains, preheating, etc.). It is recommended to extend them in the same way of "reference YML + scripts example + appending a row to this table", maintaining consistency with aliyun-domain-skills for a consistent user experience.