文档

资源编排ROS集成示例

更新时间:

使用资源编排服务ROS调用CDN。本文为您介绍如何编写一个资源编排的模板,自动化添加一个CDN的加速域名。

支持资源列表

资源编排服务ROS(Resource Orchestration Service)是阿里云提供的一项简化云计算资源管理的服务。开发者和管理员可以编写模板,在模板中定义所需的阿里云资源(例如:ECS 实例、RDS 数据库实例)、资源间的依赖关系等。ROS 的编排引擎将根据模板自动完成所有资源的创建和配置,实现自动化部署及运维。更多详情,请参见什么是资源编排服务

支持使用资源编排服务ROS调用CDN。编排的部分资源包括普通资源和数据资源。

权限说明

在本案例中,需要添加一个加速域名。默认情况下资源编排直接使用当前登录控制台的用户凭证,要求当前用户必须具备以下权限:

  • AliyunCDNFullAccess: 管理CDN资源的权限。

阿里云账号拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维。请根据业务的实际情况按需分配权限后进行接口调用。RAM用户需具备操作CDN资源的权限。具体操作,请参见CDN系统权限策略参考

操作步骤

操作步骤

  1. 登录资源编排ROS控制台,单击顶部导航栏地域下拉框,选择您需要的地域。

  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