全部產品
Search
文件中心

Resource Orchestration Service:ALIYUN::ALB::LoadBalancer

更新時間:Feb 06, 2026

ALIYUN::ALB::LoadBalancer類型用於建立應用型負載平衡ALB執行個體。

文法

{
  "Type": "ALIYUN::ALB::LoadBalancer",
  "Properties": {
    "BandwidthPackageId": String,
    "LoadBalancerName": String,
    "LoadBalancerEdition": String,
    "VpcId": String,
    "ResourceGroupId": String,
    "LoadBalancerBillingConfig": Map,
    "AddressType": String,
    "AddressAllocatedMode": String,
    "ZoneMappings": List,
    "DeletionProtectionEnabled": Boolean,
    "AddressIpVersion": String,
    "ModificationProtectionConfig": Map,
    "Tags": List,
    "AccessLogConfig": Map,
    "SecurityGroupIds": List,
    "Ipv6AddressType": String
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

AddressType

String

ALB執行個體的地址類型。

取值:

  • Internet:公網IP地址。

    DNS網域名稱被解析到公網IP地址,因此可以在公網環境訪問。

  • Intranet:私網IP地址。

    DNS網域名稱被解析到私網IP地址,因此只能被負載平衡所在的VPC內網環境訪問。

LoadBalancerBillingConfig

Map

計費配置。

更多資訊,請參見LoadBalancerBillingConfig屬性

LoadBalancerEdition

String

ALB執行個體的版本。

取值:

  • Basic:基礎版。

  • Standard:標準版。

  • StandardWithWaf:WAF 增強版。

VpcId

String

專用網路ID。

ZoneMappings

List

可用性區域及交換器映射列表。

您必須至少指定兩個可用性區域。更多資訊,請參見ZoneMappings屬性

AccessLogConfig

Map

訪問日誌配置。

更多資訊,請參見AccessLogConfig屬性

AddressAllocatedMode

String

地址模式。

取值:

  • Fixed:固定IP模式,表示使用固定的IP地址。

  • Dynamic(預設值):動態IP模式,表示每個可用性區域動態分配IP地址。

AddressIpVersion

String

Server Load Balancer執行個體的IP版本。

取值:

  • IPv4:IPv4版本。

  • DualStack:雙棧類型。

BandwidthPackageId

String

綁定的共用頻寬包ID。

當AddressType取值為Internet時,該參數有效。

DeletionProtectionEnabled

Boolean

是否啟用刪除保護。

取值:

  • true:啟用刪除保護。

  • false(預設值):禁用刪除保護。

Ipv6AddressType

String

ALB執行個體用於提供服務的IPv6地址類型。

取值: Internet:ALB執行個體使用公用IPv6地址。ALB執行個體的網域名稱被解析為公用IPv6地址。 Intranet:ALB執行個體使用私人IPv6地址。ALB執行個體的網域名稱被解析為私人IP地址。

LoadBalancerName

String

ALB執行個體的名稱。

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

不指定該參數時,預設由系統分配一個執行個體名稱。

ModificationProtectionConfig

Map

修改保護的配置。

更多資訊,請參見ModificationProtectionConfig屬性

ResourceGroupId

String

資源群組ID。

SecurityGroupIds

List

應用型Server Load Balancer執行個體需要綁定的安全性群組 ID 集合。

安全性群組功能預設不開放,如需使用,請向商務經理申請。

Tags

List

ALB執行個體的標籤。

最多支援添加20個標籤。

更多資訊,請參見Tags屬性

AccessLogConfig文法

"AccessLogConfig": {
  "Enable": Boolean,
  "LogStore": String,
  "LogProject": String 
}

AccessLogConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

LogProject

String

記錄項目。

LogStore

String

日誌儲存。

Enable

Boolean

是否啟用訪問日誌配置。

取值:

  • true:啟用訪問日誌配置。

  • false:不啟用訪問日誌配置。

LoadBalancerBillingConfig文法

"LoadBalancerBillingConfig": {
  "PayType": String
}

LoadBalancerBillingConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

PayType

String

ALB執行個體的計費方式。

取值:PostPay,表示隨用隨付。

ZoneMappings文法

"ZoneMappings": [
  {
    "ZoneId": String,
    "VSwitchId": String,
    "AllocationId": String,
    "LoadBalancerAddresses": List,
    "IntranetAddress": String,
    "EipType": String
  }
]

ZoneMappings屬性

屬性名稱

類型

必須

允許更新

描述

約束

VSwitchId

String

交換器ID。

每個可用性區域只能包含一個交換器。

ZoneId

String

可用性區域ID。

AllocationId

String

與ALB執行個體關聯的EIP (elastic IP address) ID。 

EipType

String

公網 EIP 的類型。

取值:

  • Common:彈性公網 IP,簡稱 EIP。

  • Anycast:任播彈性公網 IP,簡稱 Anycast EIP。

說明

ALB 支援綁定 Anycast EIP 的地區,請參見ALB綁定Anycast EIP實現多地區業務就近接入

LoadBalancerAddresses

List

執行個體地址。

更多資訊,請參見LoadBalancerAddresses屬性

IntranetAddress

String

IPv4 私網地址。

LoadBalancerAddresses文法

"ModificationProtectionConfig": {
  "AllocationId": String,
  "IntranetAddress": String,
  "EipType": String
}

LoadBalancerAddresses屬性

屬性名稱

類型

必須

允許更新

描述

約束

AllocationId

String

與ALB執行個體關聯的EIP (elastic IP address) ID。

EipType

String

公網 EIP 的類型。

取值:

  • Common:彈性公網 IP,簡稱 EIP。

  • Anycast:任播彈性公網 IP,簡稱 Anycast EIP。

說明

ALB 支援綁定 Anycast EIP 的地區,請參見ALB綁定Anycast EIP實現多地區業務就近接入

IntranetAddress

String

IPv4 私網地址。

ModificationProtectionConfig文法

"ModificationProtectionConfig": {
  "Status": String,
  "Reason": String
}

ModificationProtectionConfig屬性

屬性名稱

類型

必須

允許更新

描述

約束

Status

String

修改保護的狀態。

取值:

  • NonProtection:未啟用修改保護。此時不允許指定Reason參數。

  • ConsoleProtection:已啟用控制台修改保護。此時允許指定Reason參數。

Reason

String

修改保護的原因。

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

說明

當Status取值為ConsoleProtection時,該參數有效。

Tags文法

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

Tags屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

標籤鍵。

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

Value

String

標籤值。

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

傳回值

Fn::GetAtt

  • LoadBalancerEdition:ALB執行個體的版本。

  • VpcId:專用網路ID。

  • LoadBalancerId:ALB執行個體ID。

  • AddressType:ALB執行個體的地址類型。

  • DNSName:ALB執行個體的網域名稱。

  • ZoneMappings:可用性區域及交換器映射列表。

  • Arn:阿里雲資源名稱。

樣本

情境 1 :應用型負載平衡ALB執行個體

快速建立

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  ZoneMappings:
    Type: Json
    Description: The zones and the vSwitches in the zones. You must specify at least two zones.
    Default:
      - ZoneId: cn-hangzhou-h
        VSwitchId: vsw-bp1jhj254nwc7i0ge****
      - ZoneId: cn-hangzhou-i
        VSwitchId: vsw-bp1llps83qqb30znp****
Resources:
  LoadBalancer:
    Type: ALIYUN::ALB::LoadBalancer
    Properties:
      LoadBalancerName: TestLoadBalancer
      LoadBalancerEdition: Basic
      VpcId:
        Ref: VpcId
      LoadBalancerBillingConfig:
        PayType: PostPay
      ZoneMappings:
        Ref: ZoneMappings
      AddressType: Internet
Outputs:
  LoadBalancerEdition:
    Description: The edition of the ALB instance.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - LoadBalancerEdition
  VpcId:
    Description: The ID of the virtual private cloud (VPC) where the ALB instance is deployed.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - VpcId
  LoadBalancerId:
    Description: The ID of the ALB instance.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - LoadBalancerId
  AddressType:
    Description: The type of IP address that the ALB instance uses to provide services.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - AddressType
  DNSName:
    Description: The domain name of the ALB instance.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - DNSName
  ZoneMappings:
    Description: The zones, vSwitches and addresses which are mapped to the zones.
    Value:
      Fn::GetAtt:
        - LoadBalancer
        - ZoneMappings                
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "VpcId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "ZoneMappings": {
      "Type": "Json",
      "Description": "The zones and the vSwitches in the zones. You must specify at least two zones.",
      "Default": [
        {
          "ZoneId": "cn-hangzhou-h",
          "VSwitchId": "vsw-bp1jhj254nwc7i0ge****"
        },
        {
          "ZoneId": "cn-hangzhou-i",
          "VSwitchId": "vsw-bp1llps83qqb30znp****"
        }
      ]
    }
  },
  "Resources": {
    "LoadBalancer": {
      "Type": "ALIYUN::ALB::LoadBalancer",
      "Properties": {
        "LoadBalancerName": "TestLoadBalancer",
        "LoadBalancerEdition": "Basic",
        "VpcId": {
          "Ref": "VpcId"
        },
        "LoadBalancerBillingConfig": {
          "PayType": "PostPay"
        },
        "ZoneMappings": {
          "Ref": "ZoneMappings"
        },
        "AddressType": "Internet"
      }
    }
  },
  "Outputs": {
    "LoadBalancerEdition": {
      "Description": "The edition of the ALB instance.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "LoadBalancerEdition"
        ]
      }
    },
    "VpcId": {
      "Description": "The ID of the virtual private cloud (VPC) where the ALB instance is deployed.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "VpcId"
        ]
      }
    },
    "LoadBalancerId": {
      "Description": "The ID of the ALB instance.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "LoadBalancerId"
        ]
      }
    },
    "AddressType": {
      "Description": "The type of IP address that the ALB instance uses to provide services.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "AddressType"
        ]
      }
    },
    "DNSName": {
      "Description": "The domain name of the ALB instance.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "DNSName"
        ]
      }
    },
    "ZoneMappings": {
      "Description": "The zones, vSwitches and addresses which are mapped to the zones.",
      "Value": {
        "Fn::GetAtt": [
          "LoadBalancer",
          "ZoneMappings"
        ]
      }
    }
  }
}

情境 2 :建立雙可用性區域ALB負載平衡,搭配ESS自動擴縮容

快速建立

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 建立雙可用性區域ALB負載平衡,搭配ESS自動擴縮容,確保應用高可用性,含安全性群組與自動安裝nginx配置。
  en: Create a dual-Availability-Zone ALB (Application Load Balancer) along with ESS
    (Elastic Scale Service) for automatic scaling, ensuring high application availability,
    inclusive of security groups and automated installation of nginx configurations.
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
  ScalingTime:
    Type: String
    Label:
      en: Automatic expansion execution time
      zh-cn: 自動擴容執行時間
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDThh:mmZ'
    Description:
      zh-cn: 本方案建立完成預計需要 3-5 分鐘,建議選擇 5 分鐘之後的時間觀察擴容效果。
      en: >-
        It is estimated that it will take 3-5 minutes to complete the creation of this solution. 
        It is recommended to choose a time after 5 minutes to observe the expansion effect.
  ScalingTime2:
    Type: String
    Label:
      en: Automatic scaling execution time
      zh-cn: 自動縮容執行時間
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDThh:mmZ'
    Description:
      zh-cn: 建議選擇擴容時間之後的 5-10 分鐘觀察縮容效果。
      en: It is recommended to observe the shrinkage effect 5-10 minutes after the expansion time.
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
  AlbListener:
    Type: 'ALIYUN::ALB::Listener'
    Properties:
      ListenerPort: 80
      DefaultActions:
        - Type: ForwardGroup
          ForwardGroupConfig:
            ServerGroupTuples:
              - ServerGroupId:
                  Ref: AlbServerGroup
      LoadBalancerId:
        Ref: Alb
      ListenerProtocol: HTTP
  EssScalingGroup:
    Type: 'ALIYUN::ESS::ScalingGroup'
    Properties:
      VSwitchIds:
        - Ref: VSwitch1
        - Ref: VSwitch2
      ScalingGroupName:
        Fn::Sub: ${CommonName}-${ALIYUN::StackId}
      RemovalPolicys:
        - NewestInstance
      MinSize: 0
      MaxSize: 4
      DefaultCooldown: 300
      MultiAZPolicy: COMPOSABLE
      AzBalance: true
    DependsOn: SecurityGroup
  EssServerGroupAttachment:
    Type: 'ALIYUN::ESS::ServerGroupAttachment'
    DependsOn: EssScalingGroupEnable
    Properties:
      ScalingGroupId:
        Ref: EssScalingGroup
      ForceAttach: true
      ServerGroups:
        - Type: ALB
          Port: 80
          ServerGroupId:
            Ref: AlbServerGroup
          Weight: 100
  EssScalingConfiguration:
    Type: 'ALIYUN::ESS::ScalingConfiguration'
    Properties:
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
      ScalingConfigurationName:
        Fn::Sub: ${CommonName}-asc
      ScalingGroupId:
        Ref: EssScalingGroup
      InstanceTypes:
        - Ref: InstanceType1
        - Ref: InstanceType2
      SystemDiskCategory: cloud_essd
      SystemDiskSize: 40
      Password:
        Ref: InstancePassword
      InstanceName:
        Fn::Sub: ${CommonName}-ess
      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 instance from ess, the instance id is $instanceId" > /usr/share/nginx/html/index.html 
          systemctl start nginx 
          systemctl enable nginx
  EssScalingGroupEnable:
    Type: 'ALIYUN::ESS::ScalingGroupEnable'
    Properties:
      ScalingGroupId:
        Ref: EssScalingGroup
      ScalingConfigurationId:
        Ref: EssScalingConfiguration
  EssScalingRule:
    Type: 'ALIYUN::ESS::ScalingRule'
    Properties:
      ScalingRuleName:
        Fn::Sub: ${CommonName}-asr-rule
      ScalingGroupId:
        Ref: EssScalingGroup
      ScalingRuleType: SimpleScalingRule
      AdjustmentType: QuantityChangeInCapacity
      AdjustmentValue: 1
      Cooldown: 60
  EssScalingRule2:
    Type: 'ALIYUN::ESS::ScalingRule'
    Properties:
      ScalingRuleName:
        Fn::Sub: ${CommonName}-asr-rule2
      ScalingGroupId:
        Ref: EssScalingGroup
      ScalingRuleType: SimpleScalingRule
      AdjustmentType: QuantityChangeInCapacity
      AdjustmentValue: -1
      Cooldown: 60
  EssScheduledTask:
    Type: 'ALIYUN::ESS::ScheduledTask'
    Properties:
      ScheduledTaskName:
        Fn::Sub: ${CommonName}-task1-${ALIYUN::StackId}
      LaunchTime:
        Ref: ScalingTime
      ScheduledAction:
        Fn::Sub: '${EssScalingRule.ScalingRuleAri}'
      LaunchExpirationTime: 10
  EssScheduledTask2:
    Type: 'ALIYUN::ESS::ScheduledTask'
    Properties:
      ScheduledTaskName:
        Fn::Sub: ${CommonName}-task2-${ALIYUN::StackId}
      LaunchTime:
        Ref: ScalingTime2
      ScheduledAction:
        Fn::Sub: '${EssScalingRule2.ScalingRuleAri}'
      LaunchExpirationTime: 10
Outputs:
  WebUrl:
    Description:
      zh-cn: Web 存取地址。
      en: The Addresses of Web.
    Value:
      'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
  'ALIYUN::ROS::Interface':
    ParameterGroups:
      - Parameters:
          - ZoneId1
          - ZoneId2
          - InstanceType1
          - InstanceType2
          - InstancePassword
          - ScalingTime
          - ScalingTime2
    TemplateTags:
      - acs:technical-solution:high-availability-architecture:通過ALB+ESS提升應用的可用性-tech_solu_117
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "建立雙可用性區域ALB負載平衡,搭配ESS自動擴縮容,確保應用高可用性,含安全性群組與自動安裝nginx配置。",
    "en": "Create a dual-Availability-Zone ALB (Application Load Balancer) along with ESS (Elastic Scale Service) for automatic scaling, ensuring high application availability, inclusive of security groups and automated installation of nginx configurations."
  },
  "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
    },
    "ScalingTime": {
      "Type": "String",
      "Label": {
        "en": "Automatic expansion execution time",
        "zh-cn": "自動擴容執行時間"
      },
      "AssociationProperty": "DateTime",
      "AssociationPropertyMetadata": {
        "Format": "YYYY-MM-DDThh:mmZ"
      },
      "Description": {
        "zh-cn": "本方案建立完成預計需要 3-5 分鐘,建議選擇 5 分鐘之後的時間觀察擴容效果。",
        "en": "It is estimated that it will take 3-5 minutes to complete the creation of this solution.  It is recommended to choose a time after 5 minutes to observe the expansion effect."
      }
    },
    "ScalingTime2": {
      "Type": "String",
      "Label": {
        "en": "Automatic scaling execution time",
        "zh-cn": "自動縮容執行時間"
      },
      "AssociationProperty": "DateTime",
      "AssociationPropertyMetadata": {
        "Format": "YYYY-MM-DDThh:mmZ"
      },
      "Description": {
        "zh-cn": "建議選擇擴容時間之後的 5-10 分鐘觀察縮容效果。",
        "en": "It is recommended to observe the shrinkage effect 5-10 minutes after the expansion time."
      }
    }
  },
  "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
          }
        ]
      }
    },
    "AlbListener": {
      "Type": "ALIYUN::ALB::Listener",
      "Properties": {
        "ListenerPort": 80,
        "DefaultActions": [
          {
            "Type": "ForwardGroup",
            "ForwardGroupConfig": {
              "ServerGroupTuples": [
                {
                  "ServerGroupId": {
                    "Ref": "AlbServerGroup"
                  }
                }
              ]
            }
          }
        ],
        "LoadBalancerId": {
          "Ref": "Alb"
        },
        "ListenerProtocol": "HTTP"
      }
    },
    "EssScalingGroup": {
      "Type": "ALIYUN::ESS::ScalingGroup",
      "Properties": {
        "VSwitchIds": [
          {
            "Ref": "VSwitch1"
          },
          {
            "Ref": "VSwitch2"
          }
        ],
        "ScalingGroupName": {
          "Fn::Sub": "${CommonName}-${ALIYUN::StackId}"
        },
        "RemovalPolicys": [
          "NewestInstance"
        ],
        "MinSize": 0,
        "MaxSize": 4,
        "DefaultCooldown": 300,
        "MultiAZPolicy": "COMPOSABLE",
        "AzBalance": true
      },
      "DependsOn": "SecurityGroup"
    },
    "EssServerGroupAttachment": {
      "Type": "ALIYUN::ESS::ServerGroupAttachment",
      "DependsOn": "EssScalingGroupEnable",
      "Properties": {
        "ScalingGroupId": {
          "Ref": "EssScalingGroup"
        },
        "ForceAttach": true,
        "ServerGroups": [
          {
            "Type": "ALB",
            "Port": 80,
            "ServerGroupId": {
              "Ref": "AlbServerGroup"
            },
            "Weight": 100
          }
        ]
      }
    },
    "EssScalingConfiguration": {
      "Type": "ALIYUN::ESS::ScalingConfiguration",
      "Properties": {
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd",
        "ScalingConfigurationName": {
          "Fn::Sub": "${CommonName}-asc"
        },
        "ScalingGroupId": {
          "Ref": "EssScalingGroup"
        },
        "InstanceTypes": [
          {
            "Ref": "InstanceType1"
          },
          {
            "Ref": "InstanceType2"
          }
        ],
        "SystemDiskCategory": "cloud_essd",
        "SystemDiskSize": 40,
        "Password": {
          "Ref": "InstancePassword"
        },
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ess"
        },
        "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 instance from ess, the instance id is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
        }
      }
    },
    "EssScalingGroupEnable": {
      "Type": "ALIYUN::ESS::ScalingGroupEnable",
      "Properties": {
        "ScalingGroupId": {
          "Ref": "EssScalingGroup"
        },
        "ScalingConfigurationId": {
          "Ref": "EssScalingConfiguration"
        }
      }
    },
    "EssScalingRule": {
      "Type": "ALIYUN::ESS::ScalingRule",
      "Properties": {
        "ScalingRuleName": {
          "Fn::Sub": "${CommonName}-asr-rule"
        },
        "ScalingGroupId": {
          "Ref": "EssScalingGroup"
        },
        "ScalingRuleType": "SimpleScalingRule",
        "AdjustmentType": "QuantityChangeInCapacity",
        "AdjustmentValue": 1,
        "Cooldown": 60
      }
    },
    "EssScalingRule2": {
      "Type": "ALIYUN::ESS::ScalingRule",
      "Properties": {
        "ScalingRuleName": {
          "Fn::Sub": "${CommonName}-asr-rule2"
        },
        "ScalingGroupId": {
          "Ref": "EssScalingGroup"
        },
        "ScalingRuleType": "SimpleScalingRule",
        "AdjustmentType": "QuantityChangeInCapacity",
        "AdjustmentValue": -1,
        "Cooldown": 60
      }
    },
    "EssScheduledTask": {
      "Type": "ALIYUN::ESS::ScheduledTask",
      "Properties": {
        "ScheduledTaskName": {
          "Fn::Sub": "${CommonName}-task1-${ALIYUN::StackId}"
        },
        "LaunchTime": {
          "Ref": "ScalingTime"
        },
        "ScheduledAction": {
          "Fn::Sub": "${EssScalingRule.ScalingRuleAri}"
        },
        "LaunchExpirationTime": 10
      }
    },
    "EssScheduledTask2": {
      "Type": "ALIYUN::ESS::ScheduledTask",
      "Properties": {
        "ScheduledTaskName": {
          "Fn::Sub": "${CommonName}-task2-${ALIYUN::StackId}"
        },
        "LaunchTime": {
          "Ref": "ScalingTime2"
        },
        "ScheduledAction": {
          "Fn::Sub": "${EssScalingRule2.ScalingRuleAri}"
        },
        "LaunchExpirationTime": 10
      }
    }
  },
  "Outputs": {
    "WebUrl": {
      "Description": {
        "zh-cn": "Web 存取地址。",
        "en": "The Addresses of Web."
      },
      "Value": {
        "Fn::Sub": "http://${Alb.DNSName}"
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "ZoneId1",
            "ZoneId2",
            "InstanceType1",
            "InstanceType2",
            "InstancePassword",
            "ScalingTime",
            "ScalingTime2"
          ]
        }
      ],
      "TemplateTags": [
        "acs:technical-solution:high-availability-architecture:通過ALB+ESS提升應用的可用性-tech_solu_117"
      ],
      "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"
      ]
    }
  }
}

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