使用資源編排服務ROS調用CDN。本文為您介紹如何編寫一個資源編排的模板,自動化添加一個CDN的加速域名。
支持資源列表
資源編排服務ROS(Resource Orchestration Service)是阿里云提供的一項簡化云計算資源管理的服務。開發者和管理員可以編寫模板,在模板中定義所需的阿里云資源(例如:ECS 實例、RDS 數據庫實例)、資源間的依賴關系等。ROS 的編排引擎將根據模板自動完成所有資源的創建和配置,實現自動化部署及運維。更多詳情,請參見什么是資源編排服務。
支持使用資源編排服務ROS調用CDN。編排的部分資源包括普通資源和數據資源。
普通資源:
ALIYUN::CDN::Domain:用于添加加速域名。
ALIYUN::CDN::DomainConfig:用于批量配置域名。
數據資源:
DATASOURCE::CDN::Domains:用于查詢已創建加速域名的基礎信息
權限說明
在本案例中,需要添加一個加速域名。默認情況下資源編排直接使用當前登錄控制臺的用戶憑證,要求當前用戶必須具備以下權限:
AliyunCDNFullAccess: 管理CDN資源的權限。
阿里云賬號擁有所有API的訪問權限,風險很高。強烈建議您創建并使用RAM用戶進行API訪問或日常運維。請根據業務的實際情況按需分配權限后進行接口調用。RAM用戶需具備操作CDN資源的權限。具體操作,請參見CDN系統權限策略參考。
操作步驟
操作步驟
登錄資源編排ROS控制臺,單擊頂部導航欄地域下拉框,選擇您需要的地域。
單擊左側菜單欄中的資源棧,選擇
。指定模板:選中選擇已有模板。
模板錄入方式:選中輸入模板。
模板內容選擇ROS,并輸入代碼。
添加加速域名的語法、說明及示例,請參見ALIYUN::CDN::Domain。
ROSTemplateFormatVersion: '2015-09-01' Parameters: CdnType: AllowedValues: - video - download - web - liveStream Description: 'The business type. Valid values: web, download, video, livestream, and httpsdelivery. web: acceleration of images and small files download. download: acceleration of large file downloads. video: live streaming acceleration. httpsdelivery: SSL acceleration for HTTPS.' Type: String CheckUrl: Description: The validation of the origin. Type: String DomainName: Description: The CDN domain name. Wildcard domain names that start with periods (.) are supported. For example, .example.com. Type: String ResourceGroupId: Description: The ID of the resource group. If this is left blank, the system automatically fills in the ID of the default resource group. Type: String Scope: Description: 'Valid values: domestic, overseas, and global. Default value: domestic. The setting is supported for users outside mainland China, users in mainland China of level 3 or above.' Type: String Sources: Description: The list of origin URLs. Type: String Tags: Description: Tags to attach to instance. Max support 20 tags to add during create instance. Each tag with two properties Key and Value, and Key is required. MaxLength: 20 Type: Json TopLevelDomain: Description: The top-level domain, which can only be configured by users on the whitelist. Type: String Resources: Domain: Properties: CdnType: Ref: CdnType CheckUrl: Ref: CheckUrl DomainName: Ref: DomainName ResourceGroupId: Ref: ResourceGroupId Scope: Ref: Scope Sources: Ref: Sources Tags: Ref: Tags TopLevelDomain: Ref: TopLevelDomain Type: ALIYUN::CDN::Domain Outputs: Cname: Description: The CNAME generated for the CDN domain.You must add a CNAME record with your DNS provider to map the CDN domain name to the CNAME. Value: Fn::GetAtt: - Domain - Cname DomainName: Description: The CDN domain name. Wildcard domain names that start with periods (.) are supported. For example, .example.com. Value: Fn::GetAtt: - Domain - DomainName
{ "ROSTemplateFormatVersion": "2015-09-01", "Parameters": { "CheckUrl": { "Type": "String", "Description": "The validation of the origin." }, "ResourceGroupId": { "Type": "String", "Description": "The ID of the resource group. If this is left blank, the system automatically fills in the ID of the default resource group." }, "Scope": { "Type": "String", "Description": "Valid values: domestic, overseas, and global. Default value: domestic. The setting is supported for users outside mainland China, users in mainland China of level 3 or above." }, "DomainName": { "Type": "String", "Description": "The CDN domain name. Wildcard domain names that start with periods (.) are supported. For example, .example.com." }, "CdnType": { "Type": "String", "Description": "The business type. Valid values: web, download, video, livestream, and httpsdelivery. web: acceleration of images and small files download. download: acceleration of large file downloads. video: live streaming acceleration. httpsdelivery: SSL acceleration for HTTPS.", "AllowedValues": [ "video", "download", "web", "liveStream" ] }, "TopLevelDomain": { "Type": "String", "Description": "The top-level domain, which can only be configured by users on the whitelist." }, "Sources": { "Type": "String", "Description": "The list of origin URLs." }, "Tags": { "Type": "Json", "Description": "Tags to attach to instance. Max support 20 tags to add during create instance. Each tag with two properties Key and Value, and Key is required.", "MaxLength": 20 } }, "Resources": { "Domain": { "Type": "ALIYUN::CDN::Domain", "Properties": { "CheckUrl": { "Ref": "CheckUrl" }, "ResourceGroupId": { "Ref": "ResourceGroupId" }, "Scope": { "Ref": "Scope" }, "DomainName": { "Ref": "DomainName" }, "CdnType": { "Ref": "CdnType" }, "TopLevelDomain": { "Ref": "TopLevelDomain" }, "Sources": { "Ref": "Sources" }, "Tags": { "Ref": "Tags" } } } }, "Outputs": { "DomainName": { "Description": "The CDN domain name. Wildcard domain names that start with periods (.) are supported. For example, .example.com.", "Value": { "Fn::GetAtt": [ "Domain", "DomainName" ] } }, "Cname": { "Description": "The CNAME generated for the CDN domain.You must add a CNAME record with your DNS provider to map the CDN domain name to the CNAME.", "Value": { "Fn::GetAtt": [ "Domain", "Cname" ] } } } }
單擊下一步,執行操作棧。
在配置參數頁面配置參數,單擊創建。
輸出結果。
創建完成后,您可以通過OpenAPI、SDK或者在CDN控制臺,可以查看到。