全部產品
Search
文件中心

CDN:Resource Orchestration Service整合樣本

更新時間:Oct 25, 2024

使用Resource Orchestration Service服務ROS調用CDN。本文為您介紹如何編寫一個Resource Orchestration Service的模板,自動化添加一個CDN的加速網域名稱。

支援資源清單

Resource Orchestration Service服務ROS(Resource Orchestration Service)是阿里雲提供的一項簡化雲端運算資源管理的服務。開發人員和管理員可以編寫模板,在模板中定義所需的阿里雲資源(例如:ECS 執行個體、RDS 資料庫執行個體)、資源間的依賴關係等。ROS 的編排引擎將根據模板自動完成所有資源的建立和配置,實現自動化部署及營運。更多詳情,請參見什麼是Resource Orchestration Service服務

支援使用Resource Orchestration Service服務ROS調用CDN。編排的部分資源套件括普通資源和資料資源。

許可權說明

在本案例中,需要添加一個加速網域名稱。預設情況下Resource Orchestration Service直接使用當前登入控制台的使用者憑證,要求目前使用者必須具備以下許可權:

  • AliyunCDNFullAccess: 管理CDN資源的許可權。

阿里雲帳號擁有所有API的存取權限,風險很高。強烈建議您建立並使用RAM使用者進行API訪問或日常營運。請根據業務的實際情況按需分配許可權後進行介面調用。RAM使用者需具備操作CDN資源的許可權。具體操作,請參見CDN系統權限原則參考

操作步驟

操作步驟

  1. 登入Resource Orchestration Service控制台,單擊頂部導覽列地區下拉框,選擇您需要的地區。

  2. 單擊左側功能表列中的資源棧,選擇建立資源棧 > 使用ROS

    • 指定模板:選中選擇已有模板

    • 模板錄入方式:選中輸入模板

  3. 模板內容選擇ROS,並輸入代碼。

    添加加速網域名稱的文法、說明及樣本,請參見ALIYUN::CDN::Domain

    YAML格式

    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

    JSON格式

    {
     "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"
        ]
       }
      }
     }
    }
  4. 單擊下一步,執行操作棧。

  5. 在配置參數頁面配置參數,單擊建立

  6. 輸出結果。

    image

  7. 建立完成後,您可以通過OpenAPI、SDK或者在CDN控制台,可以查看到。

    image