全部產品
Search
文件中心

Resource Orchestration Service:ALIYUN::ALB::ServerGroup

更新時間:Feb 06, 2026

ALIYUN::ALB::ServerGroup類型用於建立伺服器組。

文法

{
  "Type": "ALIYUN::ALB::ServerGroup",
  "Properties": {
    "VpcId": String,
    "ResourceGroupId": String,
    "Scheduler": String,
    "StickySessionConfig": Map,
    "HealthCheckConfig": Map,
    "Protocol": String,
    "ServerGroupType": String,
    "ServerGroupName": String,
    "Tags": List,
    "ServiceName": String,
    "UpstreamKeepaliveEnabled": Boolean,
    "SlowStartConfig": Map,
    "ConnectionDrainConfig": Map,
    "UchConfig": Map,
    "CrossZoneEnabled": Boolean,
    "Ipv6Enabled": Boolean
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

HealthCheckConfig

Map

健全狀態檢查相關配置結構。

更多資訊,請參見HealthCheckConfig屬性

ServerGroupName

String

伺服器組名稱。

長度為2~128個字元,必須以英文字母或漢字開頭,可包含數字、半形句點(.)、底線(_)和短劃線(-)。

VpcId

String

專用網路ID。

只有該VPC下的伺服器可以加入伺服器組。

Protocol

String

後端協議。

取值:

  • HTTP(預設值):支援關聯HTTPS、HTTP和QUIC監聽。

  • HTTPS:支援關聯HTTPS監聽。

  • gRPC:關聯 HTTPS 和 QUIC 監聽。

說明

ServerGroupType取值為Fc時,僅支援HTTP協議。

ResourceGroupId

String

資源群組ID。

Scheduler

String

調度演算法。

取值:

  • Wrr(預設值):權重值越高的後端伺服器,被輪詢到的機率也越高。

  • Wlc:除了根據每台後端伺服器設定的權重值來進行輪詢,同時還考慮後端伺服器的實際負載(即串連數)。當權重值相同時,當前串連數越小的後端伺服器被輪詢到的機率也越高。

  • Sch:源IP一致性Hash。

ServerGroupType

String

伺服器群組類型。

取值:

  • Instance(預設值):伺服器類型。

  • Ip:IP地址類型。

  • Fc:Function Compute類型,該類型支援添加Function Compute類型的後端伺服器。

ServiceName

String

伺服器組對應的Kubernetes服務名稱。

說明

本參數僅適用於應用路由情境。

StickySessionConfig

Map

會話保持配置結構體。

更多資訊,請參見StickySessionConfig屬性

Tags

List

標籤。

最多添加20個標籤。

更多資訊,請參見Tags屬性

UpstreamKeepaliveEnabled

Boolean

是否開啟後端長連結。

  • true:開啟

  • false(預設值):不開啟。

SlowStartConfig

Map

慢啟動相關配置。

開啟慢啟動後,將會在設定的時間段內對新添加到後端伺服器組的後端伺服器進行預熱,轉寄到該伺服器的請求數量線性增加。

更多資訊,請參見SlowStartConfig屬性

說明
  • 基礎版執行個體不支援開啟慢啟動,僅標準版、WAF 增強版執行個體支援。

  • 伺服器類型、IP 類型伺服器組支援配置慢啟動,Function Compute類型不支援。

  • 慢啟動僅在後端調度演算法是加權輪詢演算法時可開啟。

ConnectionDrainConfig

Map

串連優雅中斷相關配置。

開啟串連優雅中斷,在移除後端伺服器或者健全狀態檢查失敗後,負載平衡使現有串連在一定時間內正常傳輸。

說明

基礎版執行個體不支援開啟串連優雅中斷,僅標準版、WAF 增強版執行個體支援。

伺服器類型、IP 類型伺服器組支援串連優雅中斷,Function Compute類型不支援。

UchConfig

Map

URL一致性 hash 參數配置。

更多資訊,請參見UchConfig屬性

CrossZoneEnabled

Boolean

伺服器組是否開啟跨 AZ 負載平衡。

取值:

  • true:開啟(預設值)

  • false:關閉

說明
  • 基礎版執行個體不支援綁定關閉跨 AZ 負載平衡的伺服器組,僅標準版、WAF 增強版執行個體支援。

  • 伺服器類型、IP 類型伺服器組支援關閉跨 AZ 負載平衡,Function Compute類型不支援。

  • 關閉跨 AZ 負載平衡時,不支援開啟會話保持。

Ipv6Enabled

Boolean

是否開啟 Ipv6

UchConfig文法

"UchConfig": {
  "Type": String,
  "Value": String
}

UchConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

Type

String

參數類型。

只能填 QueryString。

Value

String

一致性 hash 參數值。

ConnectionDrainConfig文法

"ConnectionDrainConfig": {
  "ConnectionDrainTimeout": Integer,
  "ConnectionDrainEnabled": Boolean
}

ConnectionDrainConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

ConnectionDrainTimeout

Integer

串連優雅中斷逾時時間。

取值範圍:0~900

預設值:300

ConnectionDrainEnabled

Boolean

是否開啟串連優雅中斷。

取值:

  • true:啟用。

  • false:禁用。

SlowStartConfig文法

"SlowStartConfig": {
  "SlowStartDuration": Integer,
  "SlowStartEnabled": Boolean
}

SlowStartConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

SlowStartDuration

Integer

慢啟動期間。

取值範圍:30~900

預設值:30

SlowStartEnabled

Boolean

是否開啟慢啟動。

取值:

  • true:啟用。

  • false:禁用。

StickySessionConfig文法

"StickySessionConfig": {
  "Cookie": String,
  "CookieTimeout": Integer,
  "StickySessionType": String,
  "StickySessionEnabled": Boolean
}

StickySessionConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

Cookie

String

伺服器上配置的Cookie。

長度為1~200個字元,不能以貨幣符號($)開頭,可包含英文字母和數字,不能包含半形逗號(,)、半形分號(;)或空格。

說明

當StickySessionEnabled取值為true且StickySessionType取值為Server時,必須指定該參數。

CookieTimeout

Integer

Cookie逾時時間。

取值範圍:1~86,400。

預設值:1000。

單位:秒。

說明

當StickySessionEnabled取值為true且StickySessionType取值為Insert時,必須指定該參數。

StickySessionEnabled

Boolean

是否啟用會話保持。

取值:

  • true:啟用。

  • false:禁用。

說明

當ServerGroupType取值為InstanceIp時,必須指定該參數。

StickySessionType

String

Cookie的處理方式。

取值:

  • Insert(預設值):植入Cookie。用戶端第一次訪問時,負載平衡會在返回請求中植入Cookie(即在HTTP或HTTPS響應報文中插入SERVERID),下次用戶端攜帶此Cookie訪問,負載平衡服務會將請求定向轉寄給之前記錄到的後端伺服器上。

  • Server:重寫Cookie。負載平衡發現使用者自訂了Cookie,將會對原來的Cookie進行重寫,下次用戶端攜帶新的Cookie訪問,負載平衡服務會將請求定向轉寄給之前記錄到的後端伺服器。

說明

當StickySessionEnabled取值為true時,必須指定該參數。

HealthCheckConfig文法

"HealthCheckConfig": {
  "HealthCheckInterval": Integer,
  "HealthCheckConnectPort": Integer,
  "HealthCheckCodes": List,
  "UnhealthyThreshold": Integer,
  "HealthCheckMethod": String,
  "HealthCheckPath": String,
  "HealthCheckHost": String,
  "HealthyThreshold": Integer,
  "HealthCheckProtocol": String,
  "HealthCheckHttpVersion": String,
  "HealthCheckEnabled": Boolean,
  "HealthCheckTimeout": Integer
}

HealthCheckConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

HealthCheckEnabled

Boolean

是否啟用健全狀態檢查。

取值:

  • true:啟用。

  • false:禁用。

HealthCheckCodes

List

健全狀態檢查的狀態代碼列表。

取值:

  • http_2xx(預設值)

  • http_3xx

  • http_4xx

  • http_5xx

  • HealthCheckProtocol取值為gRPC時,HealthCheckCodes狀態代碼範圍:0~99,預設值:0。支援範圍輸入,最多支援 20 個範圍值。多個範圍值使用半形逗號(,)隔開。

說明

HealthCheckProtocolHTTPHTTPSgRPC,該參數生效。

HealthCheckConnectPort

Integer

健全狀態檢查的後端伺服器的連接埠。

取值範圍: 0~65,535。

預設值:0,表示使用後端伺服器的連接埠進行健全狀態檢查。

HealthCheckHost

String

健全狀態檢查網域名稱。

長度為1~80個字元。可包含小寫英文字母、數字、短劃線(-)和半形句號(.)。

取值樣本:www.example.com

說明

當HealthCheckProtocol取值為HTTP時,該參數有效。

HealthCheckHttpVersion

String

健全狀態檢查HTTP協議版本。

取值:

  • HTTP1.0

  • HTTP1.1(預設值)

說明

當HealthCheckProtocol取值為HTTP時,該參數有效。

HealthCheckInterval

Integer

健全狀態檢查的時間間隔。

取值範圍:1~50。

預設值:2。

單位:秒。

HealthCheckMethod

String

健全狀態檢查方式。

取值:

  • GET

  • HEAD(預設值)

  • POST:gRPC 監聽健全狀態檢查預設採用 POST 方法。

說明

只有HealthCheckProtocol設定為HTTPHTTPSgRPC時,該參數生效。

HealthCheckPath

String

健全狀態檢查的路徑。

長度為1~80,必須以正斜線(/)開頭。可包含英文字母、數字和特殊字元-/.%?#&=_;~!()*[]@$^:',+

說明

當HealthCheckProtocol取值為HTTP時,該參數有效。

HealthCheckProtocol

String

健全狀態檢查協議。

取值:

  • HTTP:通過發送 HEAD 或 GET 請求類比瀏覽器的訪問行為來檢查伺服器應用是否健康。

  • HTTPS:通過發送 HEAD 或 GET 請求類比瀏覽器的訪問行為來檢查伺服器應用是否健康。(資料加密,相比 HTTP 更安全。)

  • TCP:通過發送 SYN 握手報文來檢測伺服器連接埠是否存活。

  • gRPC:通過發送 POST 或 GET 請求來檢查伺服器應用是否健康。

HealthCheckTimeout

Integer

接收來自健全狀態檢查的響應需要等待的時間。

如果後端ECS在指定的時間內沒有正確響應,則判定為健全狀態檢查失敗。

取值範圍:1~300。

預設值:5。

單位:秒。

說明

如果HealthCheckTimeout的值小於HealthCheckInterval的值,則HealthCheckTimeout無效,逾時時間為HealthCheckInterval的值。

HealthyThreshold

Integer

健全狀態檢查連續成功多少次後,將後端伺服器的健全狀態檢查狀態由失敗判定為成功。

取值範圍:2~10。

預設值:3。

UnhealthyThreshold

Integer

健全狀態檢查連續失敗多少次後,將後端伺服器的健全狀態檢查狀態由成功判定為失敗。

取值範圍:2~10。

預設值:3。

Tags文法

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]  

Tags屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

標籤鍵。

長度為1~128個字元,不能以aliyunacs:開頭,不能包含http://或https:// 。

Value

String

標籤值。

長度為0~128個字元,不能以aliyunacs:開頭,不能包含http://或https:// 。

傳回值

Fn::GetAtt

  • ServerGroupId:伺服器組ID。

  • Arn:阿里雲資源名稱。

樣本

說明

請您根據實際情況更改脫敏的參數取值。

情境 1 :向伺服器組中添加後端伺服器

快速建立

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
    Type: String
    Label:
      zh-cn: 現有VPC的執行個體ID
      en: Existing VPC Instance ID
Resources:
  ServerGroup:
    Type: ALIYUN::ALB::ServerGroup
    Properties:
      VpcId:
        Ref: VpcId
      StickySessionConfig:
        Cookie: B490B5EBF6F3CD402E515D22****
        CookieTimeout: 1000
        StickySessionEnabled: true
        StickySessionType: Insert
      HealthCheckConfig:
        HealthCheckConnectPort: 80
        HealthCheckEnabled: true
        HealthCheckHost: www.example.com
        HealthCheckCodes:
          - http_2xx
        HealthCheckHttpVersion: HTTP1.0
        HealthCheckInterval: 5
        HealthCheckMethod: HEAD
        HealthCheckPath: /test/index.html
        HealthCheckProtocol: HTTP
        HealthCheckTimeout: 3
        HealthyThreshold: 4
        UnhealthyThreshold: 4
      ServerGroupName: TestServerGroup
Outputs:
  ServerGroupId:
    Description: The ID of the server group.
    Value:
      Fn::GetAtt:
        - ServerGroup
        - ServerGroupId                  
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "VpcId": {
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId",
      "Type": "String",
      "Label": {
        "zh-cn": "現有VPC的執行個體ID",
        "en": "Existing VPC Instance ID"
      }
    }
  },
  "Resources": {
    "ServerGroup": {
      "Type": "ALIYUN::ALB::ServerGroup",
      "Properties": {
        "VpcId": {
          "Ref": "VpcId"
        },
        "StickySessionConfig": {
          "Cookie": "B490B5EBF6F3CD402E515D22****",
          "CookieTimeout": 1000,
          "StickySessionEnabled": true,
          "StickySessionType": "Insert"
        },
        "HealthCheckConfig": {
          "HealthCheckConnectPort": 80,
          "HealthCheckEnabled": true,
          "HealthCheckHost": "www.example.com",
          "HealthCheckCodes": [
            "http_2xx"
          ],
          "HealthCheckHttpVersion": "HTTP1.0",
          "HealthCheckInterval": 5,
          "HealthCheckMethod": "HEAD",
          "HealthCheckPath": "/test/index.html",
          "HealthCheckProtocol": "HTTP",
          "HealthCheckTimeout": 3,
          "HealthyThreshold": 4,
          "UnhealthyThreshold": 4
        },
        "ServerGroupName": "TestServerGroup"
      }
    }
  },
  "Outputs": {
    "ServerGroupId": {
      "Description": "The ID of the server group.",
      "Value": {
        "Fn::GetAtt": [
          "ServerGroup",
          "ServerGroupId"
        ]
      }
    }
  }
}

情境 2 :建立一個應用型負載平衡ALB執行個體,並向伺服器組中添加後端伺服器

快速建立

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 建立雙可用性區域ALB負載平衡。
  en: Create a dual-Availability-Zone ALB.
Parameters:
  CommonName:
    Type: String
    Default: elastic-app
  ZoneId1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId2
    Label:
      en: Availability Zone
      zh-cn: 可用性區域1
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: 可用性區域2
  InstanceType1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: 執行個體規格1
  InstanceType2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: 執行個體規格2
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: >-
        Server login password, Length 8-30, must contain three(Capital letters,
        lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
        symbol in)
      zh-cn: >-
        伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
        中的特殊符號)
    Label:
      en: Instance Password
      zh-cn: 執行個體密碼
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: '長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符號)'
    AssociationProperty: 'ALIYUN::ECS::Instance::Password'
    Default: null
Resources:
  Vpc:
    Type: 'ALIYUN::ECS::VPC'
    Properties:
      CidrBlock: 192.168.0.0/16
      VpcName:
        Fn::Sub: ${CommonName}-vpc
  VSwitch1:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 192.168.1.0/24
      ZoneId:
        Ref: ZoneId1
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  VSwitch2:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 192.168.2.0/24
      ZoneId:
        Ref: ZoneId2
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  SecurityGroup:
    Type: 'ALIYUN::ECS::SecurityGroup'
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupName:
        Fn::Sub: ${CommonName}-sg
      SecurityGroupIngress:
        - PortRange: 443/443
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
        - PortRange: 80/80
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
  EcsInstance1:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ZoneId:
        Ref: ZoneId1
      VSwitchId:
        Ref: VSwitch1
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
      InstanceName:
        Fn::Sub: ${CommonName}-ecs-1
      InstanceType:
        Ref: InstanceType1
      SystemDiskCategory: cloud_essd
      MaxAmount: 1
      InternetMaxBandwidthOut: 0
      Password:
        Ref: InstancePassword
      UserData:
        Fn::Sub: |-
          #!/bin/bash
          yum -y install nginx-1.20.1
          instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
          echo "This is instance1, the instance id is $instanceId" > /usr/share/nginx/html/index.html 
          systemctl start nginx 
          systemctl enable nginx
  EcsInstance2:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ZoneId:
        Ref: ZoneId2
      VSwitchId:
        Ref: VSwitch2
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
      InstanceName:
        Fn::Sub: ${CommonName}-ecs-2
      InstanceType:
        Ref: InstanceType2
      SystemDiskCategory: cloud_essd
      MaxAmount: 1
      InternetMaxBandwidthOut: 0
      Password:
        Ref: InstancePassword
      UserData:
        Fn::Sub: |-
          #!/bin/bash
          yum -y install nginx-1.20.1
          instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
          echo "This is instance2, the instance id is $instanceId" > /usr/share/nginx/html/index.html 
          systemctl start nginx 
          systemctl enable nginx
  Alb:
    Type: 'ALIYUN::ALB::LoadBalancer'
    Properties:
      LoadBalancerName:
        Fn::Sub: ${CommonName}-alb
      LoadBalancerEdition: Basic
      VpcId:
        Ref: Vpc
      LoadBalancerBillingConfig:
        PayType: PostPay
      AddressType: Internet
      ZoneMappings:
        - ZoneId:
            Ref: ZoneId1
          VSwitchId:
            Ref: VSwitch1
        - ZoneId:
            Ref: ZoneId2
          VSwitchId:
            Ref: VSwitch2
  AlbServerGroup:
    Type: 'ALIYUN::ALB::ServerGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ServerGroupType: Instance
      ServerGroupName:
        Fn::Sub: ${CommonName}-server-group
      HealthCheckConfig:
        HealthCheckConnectPort: 80
        HealthCheckCodes:
          - http_2xx
          - http_3xx
        HealthCheckProtocol: HTTP
        HealthCheckEnabled: true
        HealthCheckPath: /
      StickySessionConfig:
        StickySessionEnabled: false
  AlbBackendServerAttachment:
    Type: 'ALIYUN::ALB::BackendServerAttachment'
    Properties:
      ServerGroupId:
        Ref: AlbServerGroup
      Servers:
        - ServerType: Ecs
          ServerId:
            Ref: EcsInstance1
          Port: 80
        - ServerType: Ecs
          ServerId:
            Ref: EcsInstance2
          Port: 80
Metadata:
  'ALIYUN::ROS::Interface':
    ParameterGroups:
      - Parameters:
          - ZoneId1
          - ZoneId2
          - InstanceType1
          - InstanceType2
          - InstancePassword
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "建立雙可用性區域ALB負載平衡。",
    "en": "Create a dual-Availability-Zone ALB."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Default": "elastic-app"
    },
    "ZoneId1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId2"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用性區域1"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用性區域2"
      }
    },
    "InstanceType1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "執行個體規格1"
      }
    },
    "InstanceType2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "執行個體規格2"
      }
    },
    "InstancePassword": {
      "NoEcho": true,
      "Type": "String",
      "Description": {
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "執行個體密碼"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "Default": null
    }
  },
  "Resources": {
    "Vpc": {
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "CidrBlock": "192.168.0.0/16",
        "VpcName": {
          "Fn::Sub": "${CommonName}-vpc"
        }
      }
    },
    "VSwitch1": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "192.168.1.0/24",
        "ZoneId": {
          "Ref": "ZoneId1"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "VSwitch2": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "192.168.2.0/24",
        "ZoneId": {
          "Ref": "ZoneId2"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "SecurityGroup": {
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupName": {
          "Fn::Sub": "${CommonName}-sg"
        },
        "SecurityGroupIngress": [
          {
            "PortRange": "443/443",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          },
          {
            "PortRange": "80/80",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          }
        ]
      }
    },
    "EcsInstance1": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ZoneId": {
          "Ref": "ZoneId1"
        },
        "VSwitchId": {
          "Ref": "VSwitch1"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd",
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ecs-1"
        },
        "InstanceType": {
          "Ref": "InstanceType1"
        },
        "SystemDiskCategory": "cloud_essd",
        "MaxAmount": 1,
        "InternetMaxBandwidthOut": 0,
        "Password": {
          "Ref": "InstancePassword"
        },
        "UserData": {
          "Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"This is instance1, the instance id is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
        }
      }
    },
    "EcsInstance2": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ZoneId": {
          "Ref": "ZoneId2"
        },
        "VSwitchId": {
          "Ref": "VSwitch2"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd",
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ecs-2"
        },
        "InstanceType": {
          "Ref": "InstanceType2"
        },
        "SystemDiskCategory": "cloud_essd",
        "MaxAmount": 1,
        "InternetMaxBandwidthOut": 0,
        "Password": {
          "Ref": "InstancePassword"
        },
        "UserData": {
          "Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"This is instance2, the instance id is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
        }
      }
    },
    "Alb": {
      "Type": "ALIYUN::ALB::LoadBalancer",
      "Properties": {
        "LoadBalancerName": {
          "Fn::Sub": "${CommonName}-alb"
        },
        "LoadBalancerEdition": "Basic",
        "VpcId": {
          "Ref": "Vpc"
        },
        "LoadBalancerBillingConfig": {
          "PayType": "PostPay"
        },
        "AddressType": "Internet",
        "ZoneMappings": [
          {
            "ZoneId": {
              "Ref": "ZoneId1"
            },
            "VSwitchId": {
              "Ref": "VSwitch1"
            }
          },
          {
            "ZoneId": {
              "Ref": "ZoneId2"
            },
            "VSwitchId": {
              "Ref": "VSwitch2"
            }
          }
        ]
      }
    },
    "AlbServerGroup": {
      "Type": "ALIYUN::ALB::ServerGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ServerGroupType": "Instance",
        "ServerGroupName": {
          "Fn::Sub": "${CommonName}-server-group"
        },
        "HealthCheckConfig": {
          "HealthCheckConnectPort": 80,
          "HealthCheckCodes": [
            "http_2xx",
            "http_3xx"
          ],
          "HealthCheckProtocol": "HTTP",
          "HealthCheckEnabled": true,
          "HealthCheckPath": "/"
        },
        "StickySessionConfig": {
          "StickySessionEnabled": false
        }
      }
    },
    "AlbBackendServerAttachment": {
      "Type": "ALIYUN::ALB::BackendServerAttachment",
      "Properties": {
        "ServerGroupId": {
          "Ref": "AlbServerGroup"
        },
        "Servers": [
          {
            "ServerType": "Ecs",
            "ServerId": {
              "Ref": "EcsInstance1"
            },
            "Port": 80
          },
          {
            "ServerType": "Ecs",
            "ServerId": {
              "Ref": "EcsInstance2"
            },
            "Port": 80
          }
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "ZoneId1",
            "ZoneId2",
            "InstanceType1",
            "InstanceType2",
            "InstancePassword"
          ]
        }
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}

情境 3 :搭建高可用的 nginx 網站

快速建立

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。
  en: Establish a dual-Availability Zone high-availability NGINX website, encompassing
    a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application
    Load Balancer (ALB), Security Groups, and automated deployment configurations.
Parameters:
  CommonName:
    Type: String
    Default: elastic-app
  ZoneId1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      AutoSelectFirst: true
      ExclusiveTo:
        - ZoneId2
    Label:
      en: Availability Zone
      zh-cn: 可用性區域1
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      AutoSelectFirst: true
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: 可用性區域2
  InstanceType1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      SpotStrategy: SpotAsPriceGo
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: 執行個體規格1
    Description:
      zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
      en: >-
        This solution will create a spot instance and automatically deploy a 
        nginx service.
    Default: null
  InstanceType2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      SpotStrategy: SpotAsPriceGo
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: 執行個體規格2
    Description:
      zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
      en: >-
        This solution will create a spot instance and automatically deploy a 
        nginx service.
    Default: null
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: >-
        Server login password, Length 8-30, must contain three(Capital letters,
        lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
        symbol in)
      zh-cn: >-
        伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
        中的特殊符號)
    Label:
      en: Instance Password
      zh-cn: 執行個體密碼
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: '長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符號)'
    AssociationProperty: 'ALIYUN::ECS::Instance::Password'
    Default: null
Resources:
  Vpc:
    Type: 'ALIYUN::ECS::VPC'
    Properties:
      CidrBlock: 192.168.0.0/16
      VpcName:
        Fn::Sub: ${CommonName}-vpc
  VSwitch1:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 192.168.1.0/24
      ZoneId:
        Ref: ZoneId1
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  VSwitch2:
    Type: 'ALIYUN::ECS::VSwitch'
    Properties:
      VpcId:
        Ref: Vpc
      CidrBlock: 192.168.2.0/24
      ZoneId:
        Ref: ZoneId2
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
  SecurityGroup:
    Type: 'ALIYUN::ECS::SecurityGroup'
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupName:
        Fn::Sub: ${CommonName}-sg
      SecurityGroupIngress:
        - PortRange: 443/443
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
        - PortRange: 80/80
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
  EcsInstance1:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ZoneId:
        Ref: ZoneId1
      VSwitchId:
        Ref: VSwitch1
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_
      InstanceName:
        Fn::Sub: ${CommonName}-ecs-1
      InstanceType:
        Ref: InstanceType1
      SystemDiskCategory: cloud_essd
      MaxAmount: 1
      InternetMaxBandwidthOut: 0
      SpotStrategy: SpotAsPriceGo
      Password:
        Ref: InstancePassword
      UserData:
        Fn::Sub: |-
          #!/bin/bash
          yum -y install nginx-1.20.1
          instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
          echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html 
          systemctl start nginx 
          systemctl enable nginx
  EcsInstance2:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ZoneId:
        Ref: ZoneId2
      VSwitchId:
        Ref: VSwitch2
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_
      InstanceName:
        Fn::Sub: ${CommonName}-ecs-2
      InstanceType:
        Ref: InstanceType2
      SystemDiskCategory: cloud_essd
      MaxAmount: 1
      InternetMaxBandwidthOut: 0
      SpotStrategy: SpotAsPriceGo
      Password:
        Ref: InstancePassword
      UserData:
        Fn::Sub: |-
          #!/bin/bash
          yum -y install nginx-1.20.1
          instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
          echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html 
          systemctl start nginx 
          systemctl enable nginx
  Alb:
    Type: 'ALIYUN::ALB::LoadBalancer'
    Properties:
      LoadBalancerName:
        Fn::Sub: ${CommonName}-alb
      LoadBalancerEdition: Basic
      VpcId:
        Ref: Vpc
      LoadBalancerBillingConfig:
        PayType: PostPay
      AddressType: Internet
      ZoneMappings:
        - ZoneId:
            Ref: ZoneId1
          VSwitchId:
            Ref: VSwitch1
        - ZoneId:
            Ref: ZoneId2
          VSwitchId:
            Ref: VSwitch2
  AlbServerGroup:
    Type: 'ALIYUN::ALB::ServerGroup'
    Properties:
      VpcId:
        Ref: Vpc
      ServerGroupType: Instance
      ServerGroupName:
        Fn::Sub: ${CommonName}-server-group
      HealthCheckConfig:
        HealthCheckConnectPort: 80
        HealthCheckCodes:
          - http_2xx
          - http_3xx
        HealthCheckProtocol: HTTP
        HealthCheckEnabled: true
        HealthCheckPath: /
      StickySessionConfig:
        StickySessionEnabled: false
  AlbBackendServerAttachment:
    Type: 'ALIYUN::ALB::BackendServerAttachment'
    Properties:
      ServerGroupId:
        Ref: AlbServerGroup
      Servers:
        - ServerType: Ecs
          ServerId:
            Ref: EcsInstance1
          Port: 80
        - ServerType: Ecs
          ServerId:
            Ref: EcsInstance2
          Port: 80
  AlbListener:
    Type: 'ALIYUN::ALB::Listener'
    Properties:
      ListenerPort: 80
      DefaultActions:
        - Type: ForwardGroup
          ForwardGroupConfig:
            ServerGroupTuples:
              - ServerGroupId:
                  Ref: AlbServerGroup
      LoadBalancerId:
        Ref: Alb
      ListenerProtocol: HTTP
Outputs:
  WebUrl:
    Description:
      zh-cn: Web 存取地址。
      en: The Addresses of Web.
    Value:
      'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
  'ALIYUN::ROS::Interface':
    ParameterGroups:
      - Parameters:
          - ZoneId1
          - InstanceType1
          - ZoneId2
          - InstanceType2
          - InstancePassword
    TemplateTags:
      - acs:example:彈性計算:搭建高可用的 nginx 網站
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。",
    "en": "Establish a dual-Availability Zone high-availability NGINX website, encompassing a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application Load Balancer (ALB), Security Groups, and automated deployment configurations."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Default": "elastic-app"
    },
    "ZoneId1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "AutoSelectFirst": true,
        "ExclusiveTo": [
          "ZoneId2"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用性區域1"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "AutoSelectFirst": true,
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "可用性區域2"
      }
    },
    "InstanceType1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "SpotStrategy": "SpotAsPriceGo",
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "執行個體規格1"
      },
      "Description": {
        "zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
        "en": "This solution will create a spot instance and automatically deploy a  nginx service."
      },
      "Default": null
    },
    "InstanceType2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "SpotStrategy": "SpotAsPriceGo",
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "執行個體規格2"
      },
      "Description": {
        "zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
        "en": "This solution will create a spot instance and automatically deploy a  nginx service."
      },
      "Default": null
    },
    "InstancePassword": {
      "NoEcho": true,
      "Type": "String",
      "Description": {
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "執行個體密碼"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "Default": null
    }
  },
  "Resources": {
    "Vpc": {
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "CidrBlock": "192.168.0.0/16",
        "VpcName": {
          "Fn::Sub": "${CommonName}-vpc"
        }
      }
    },
    "VSwitch1": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "192.168.1.0/24",
        "ZoneId": {
          "Ref": "ZoneId1"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "VSwitch2": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "192.168.2.0/24",
        "ZoneId": {
          "Ref": "ZoneId2"
        },
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        }
      }
    },
    "SecurityGroup": {
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupName": {
          "Fn::Sub": "${CommonName}-sg"
        },
        "SecurityGroupIngress": [
          {
            "PortRange": "443/443",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          },
          {
            "PortRange": "80/80",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          }
        ]
      }
    },
    "EcsInstance1": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ZoneId": {
          "Ref": "ZoneId1"
        },
        "VSwitchId": {
          "Ref": "VSwitch1"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_",
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ecs-1"
        },
        "InstanceType": {
          "Ref": "InstanceType1"
        },
        "SystemDiskCategory": "cloud_essd",
        "MaxAmount": 1,
        "InternetMaxBandwidthOut": 0,
        "SpotStrategy": "SpotAsPriceGo",
        "Password": {
          "Ref": "InstancePassword"
        },
        "UserData": {
          "Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
        }
      }
    },
    "EcsInstance2": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ZoneId": {
          "Ref": "ZoneId2"
        },
        "VSwitchId": {
          "Ref": "VSwitch2"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_",
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ecs-2"
        },
        "InstanceType": {
          "Ref": "InstanceType2"
        },
        "SystemDiskCategory": "cloud_essd",
        "MaxAmount": 1,
        "InternetMaxBandwidthOut": 0,
        "SpotStrategy": "SpotAsPriceGo",
        "Password": {
          "Ref": "InstancePassword"
        },
        "UserData": {
          "Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
        }
      }
    },
    "Alb": {
      "Type": "ALIYUN::ALB::LoadBalancer",
      "Properties": {
        "LoadBalancerName": {
          "Fn::Sub": "${CommonName}-alb"
        },
        "LoadBalancerEdition": "Basic",
        "VpcId": {
          "Ref": "Vpc"
        },
        "LoadBalancerBillingConfig": {
          "PayType": "PostPay"
        },
        "AddressType": "Internet",
        "ZoneMappings": [
          {
            "ZoneId": {
              "Ref": "ZoneId1"
            },
            "VSwitchId": {
              "Ref": "VSwitch1"
            }
          },
          {
            "ZoneId": {
              "Ref": "ZoneId2"
            },
            "VSwitchId": {
              "Ref": "VSwitch2"
            }
          }
        ]
      }
    },
    "AlbServerGroup": {
      "Type": "ALIYUN::ALB::ServerGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "ServerGroupType": "Instance",
        "ServerGroupName": {
          "Fn::Sub": "${CommonName}-server-group"
        },
        "HealthCheckConfig": {
          "HealthCheckConnectPort": 80,
          "HealthCheckCodes": [
            "http_2xx",
            "http_3xx"
          ],
          "HealthCheckProtocol": "HTTP",
          "HealthCheckEnabled": true,
          "HealthCheckPath": "/"
        },
        "StickySessionConfig": {
          "StickySessionEnabled": false
        }
      }
    },
    "AlbBackendServerAttachment": {
      "Type": "ALIYUN::ALB::BackendServerAttachment",
      "Properties": {
        "ServerGroupId": {
          "Ref": "AlbServerGroup"
        },
        "Servers": [
          {
            "ServerType": "Ecs",
            "ServerId": {
              "Ref": "EcsInstance1"
            },
            "Port": 80
          },
          {
            "ServerType": "Ecs",
            "ServerId": {
              "Ref": "EcsInstance2"
            },
            "Port": 80
          }
        ]
      }
    },
    "AlbListener": {
      "Type": "ALIYUN::ALB::Listener",
      "Properties": {
        "ListenerPort": 80,
        "DefaultActions": [
          {
            "Type": "ForwardGroup",
            "ForwardGroupConfig": {
              "ServerGroupTuples": [
                {
                  "ServerGroupId": {
                    "Ref": "AlbServerGroup"
                  }
                }
              ]
            }
          }
        ],
        "LoadBalancerId": {
          "Ref": "Alb"
        },
        "ListenerProtocol": "HTTP"
      }
    }
  },
  "Outputs": {
    "WebUrl": {
      "Description": {
        "zh-cn": "Web 存取地址。",
        "en": "The Addresses of Web."
      },
      "Value": {
        "Fn::Sub": "http://${Alb.DNSName}"
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "ZoneId1",
            "InstanceType1",
            "ZoneId2",
            "InstanceType2",
            "InstancePassword"
          ]
        }
      ],
      "TemplateTags": [
        "acs:example:彈性計算:搭建高可用的 nginx 網站"
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}

更多樣本,請參考包含此資源的公用模板。