All Products
Search
Document Center

Resource Orchestration Service:ALIYUN::ALB::LoadBalancer

Last Updated:Feb 06, 2026

The ALIYUN::ALB::LoadBalancer type is used to create an Application Load Balancer (ALB) instance.

Syntax

{
  "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
  }
}

Properties

Property name

Type

Required

Update allowed

Description

Constraints

AddressType

String

Yes

No

The address type of the ALB instance.

Valid values:

  • Internet: public IP address.

    Because the DNS domain name resolves to a public IP address, it can be accessed from the public network.

  • Intranet: private IP address.

    Intranet: The ALB instance uses a private IP address. The domain name of the instance is resolved to the private IP address. The instance can be accessed only within the virtual private cloud (VPC) where the instance is deployed.

LoadBalancerBillingConfig

Map

Yes

No

The billing configuration.

For more information, see LoadBalancerBillingConfig properties.

LoadBalancerEdition

String

Yes

Yes

The edition of the ALB instance.

Valid values:

  • Basic: Basic Edition.

  • Standard: Standard

  • StandardWithWaf: WAF-enabled

VpcId

String

Yes

No

The ID of the VPC.

None

ZoneMappings

List

Yes

No

The list of zones and vSwitches.

You must specify at least two zones. For more information, see ZoneMappings properties.

AccessLogConfig

Map

No

Yes

The access log configuration.

For more information, see AccessLogConfig properties.

AddressAllocatedMode

String

No

No

address mode

Valid values:

  • Fixed: A static IP address is used.

  • Dynamic (default): An IP address is dynamically assigned to each zone.

AddressIpVersion

String

No

No

The IP version of the load balancer instance.

Valid values:

  • IPv4: Internet Protocol version 4.

  • DualStack: dual-stack

BandwidthPackageId

String

No

Yes

The ID of the Internet Shared Bandwidth instance that is associated with the ALB instance.

This parameter is valid only when AddressType is set to Internet.

DeletionProtectionEnabled

Boolean

No

Yes

Specifies whether to enable deletion protection.

Valid values:

  • true: Deletion protection is enabled.

  • false (default): Deletion protection is disabled.

Ipv6AddressType

String

No

Yes

The type of IPv6 address that the ALB instance uses to provide services.

Valid values: Internet: The ALB instance uses a public IPv6 address. The domain name of the ALB instance is resolved to the public IPv6 address. Intranet: The ALB instance uses a private IPv6 address. The domain name of the ALB instance is resolved to the private IP address.

LoadBalancerName

String

No

Yes

The name of the ALB instance.

The name must be 1 to 80 characters in length. It can contain letters, digits, hyphens (-), forward slashes (/), periods (.), and underscores (_).

If you do not specify this parameter, the system automatically assigns a name to the instance.

ModificationProtectionConfig

Map

No

Yes

The configuration of modification protection.

For more information, see ModificationProtectionConfig properties.

ResourceGroupId

String

No

Yes

The ID of the resource group.

None

SecurityGroupIds

List

No

Yes

The IDs of the security groups to which the Application Load Balancer instance is added.

The security group feature is not enabled by default. To use this feature, contact your account manager.

Tags

List

No

Yes

The tags of the ALB instance.

You can add up to 20 tags.

For more information, see Tags properties.

AccessLogConfig syntax

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

AccessLogConfig properties

Property Name

Type

Required

Update allowed

Description

Constraints

LogProject

String

Yes

No

The log project.

None

LogStore

String

Yes

No

The Logstore.

None

Enable

Boolean

No

Yes

Specifies whether to enable the access log feature.

Valid values:

  • true: Enable the access log feature.

  • false: Disable the access log feature.

LoadBalancerBillingConfig syntax

"LoadBalancerBillingConfig": {
  "PayType": String
}

LoadBalancerBillingConfig properties

Property Name

Type

Required

Update allowed

Description

Constraints

PayType

String

Yes

No

The billing method of the ALB instance.

Valid value: PostPay. This value specifies the pay-as-you-go billing method.

ZoneMappings syntax

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

ZoneMappings properties

Property Name

Type

Required

Update allowed

Description

Constraints

VSwitchId

String

Yes

No

The ID of the vSwitch.

Each zone can contain only one vSwitch.

ZoneId

String

Yes

No

The ID of the zone.

None

AllocationId

String

No

No

The ID of the elastic IP address (EIP) that is associated with the ALB instance.

None

EipType

String

No

No

The type of the public EIP.

Valid values:

  • Common: Elastic IP Address (EIP).

  • Anycast: an anycast EIP.

Note

For information about the regions where ALB supports Anycast EIPs, see Associate an Anycast EIP with an ALB instance to accelerate access across regions.

LoadBalancerAddresses

List

No

No

The instance address.

For more information, see LoadBalancerAddresses properties.

IntranetAddress

String

No

No

The private IPv4 address.

None

LoadBalancerAddresses syntax

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

LoadBalancerAddresses properties

Property Name

Type

Required

Update allowed

Description

Constraints

AllocationId

String

Yes

No

The ID of the EIP that is associated with the ALB instance.

None

EipType

String

No

No

The type of the public EIP.

Valid values:

  • Common: an EIP.

  • Anycast: an anycast EIP.

Note

For information about the regions where ALB supports Anycast EIPs, see Associate an Anycast EIP with an ALB instance to accelerate access across regions.

IntranetAddress

String

No

No

The private IPv4 address.

None

ModificationProtectionConfig syntax

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

ModificationProtectionConfig properties

Property Name

Type

Required

Update allowed

Description

Constraints

Status

String

Yes

Yes

The status of modification protection.

Valid values:

  • NonProtection: Modification protection is not enabled. You cannot specify the Reason parameter.

  • ConsoleProtection: Modification protection is enabled in the console. You can specify the Reason parameter.

Reason

String

No

Yes

The reason for enabling modification protection.

The string must be 2 to 128 characters in length, start with an English letter or a Chinese character, and contain only English letters, Chinese characters, digits, periods (.), underscores (_), and hyphens (-).

Note

This parameter is valid only when Status is set to ConsoleProtection.

Tags syntax

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

Tags properties

Property Name

Type

Required

Update allowed

Description

Constraints

Key

String

Yes

No

The tag key.

The tag key must be 1 to 128 characters in length. It cannot start with aliyun or acs: and cannot contain http:// or https://.

Value

String

No

No

The tag value.

The tag value must be 0 to 128 characters in length. It cannot start with aliyun or acs: and cannot contain http:// or https://.

Return values

Fn::GetAtt

  • LoadBalancerEdition: The edition of the ALB instance.

  • VpcId: The ID of the VPC.

  • LoadBalancerId: The ID of the ALB instance.

  • AddressType: The address type of the ALB instance.

  • DNSName: The domain name of the ALB instance.

  • ZoneMappings: The list of zones and vSwitches.

  • Arn: The Alibaba Cloud Resource Name (ARN) of the resource.

Examples

Scenario 1: Application Load Balancer (ALB) instance.

Quick create

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"
        ]
      }
    }
  }
}

Scenario 2: Create a dual-zone ALB instance with ESS for automatic scaling.

Quick create

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create a dual-zone Application Load Balancer (ALB) with Auto Scaling (ESS) for automatic scaling to ensure high application availability. The template includes security groups and configurations for automatic NGINX installation.
  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: Zone 1
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: Zone 2
  InstanceType1:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: Instance Type 1
  InstanceType2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      InstanceChargeType: PostPaid
      SystemDiskCategory: cloud_essd
      ZoneId: ${ZoneId}
    Label:
      en: Instance Type
      zh-cn: Instance Type 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: >-
        The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
    Label:
      en: Instance Password
      zh-cn: Instance Password
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: 'The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
    AssociationProperty: 'ALIYUN::ECS::Instance::Password'
    Default: null
  ScalingTime:
    Type: String
    Label:
      en: Automatic expansion execution time
      zh-cn: Automatic scale-out time
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDThh:mmZ'
    Description:
      zh-cn: This solution takes 3 to 5 minutes to create. We recommend that you wait at least 5 minutes to view the scale-out effect.
      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: Automatic scale-in time
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDThh:mmZ'
    Description:
      zh-cn: We recommend that you wait 5 to 10 minutes after the scale-out is complete to view the scale-in effect.
      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: The web endpoint.
      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:Improve application availability using ALB and ESS-tech_solu_117
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create a dual-zone Application Load Balancer (ALB) with Auto Scaling (ESS) for automatic scaling to ensure high application availability. The template includes security groups and configurations for automatic NGINX installation.",
    "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": "Zone 1"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "Zone 2"
      }
    },
    "InstanceType1": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "Instance Type 1"
      }
    },
    "InstanceType2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "InstanceChargeType": "PostPaid",
        "SystemDiskCategory": "cloud_essd",
        "ZoneId": "${ZoneId}"
      },
      "Label": {
        "en": "Instance Type",
        "zh-cn": "Instance Type 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": "The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "Instance Password"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "Default": null
    },
    "ScalingTime": {
      "Type": "String",
      "Label": {
        "en": "Automatic expansion execution time",
        "zh-cn": "Automatic scale-out time"
      },
      "AssociationProperty": "DateTime",
      "AssociationPropertyMetadata": {
        "Format": "YYYY-MM-DDThh:mmZ"
      },
      "Description": {
        "zh-cn": "This solution takes 3 to 5 minutes to create. We recommend that you wait at least 5 minutes to view the scale-out effect.",
        "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": "Automatic scale-in time"
      },
      "AssociationProperty": "DateTime",
      "AssociationPropertyMetadata": {
        "Format": "YYYY-MM-DDThh:mmZ"
      },
      "Description": {
        "zh-cn": "We recommend that you wait 5 to 10 minutes after the scale-out is complete to view the scale-in effect.",
        "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": "The web endpoint.",
        "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:Improve application availability using ALB and ESS-tech_solu_117"
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}

Scenario 3: Build a high-availability NGINX website.

Quick create

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Build a high-availability NGINX website across two zones. The template includes a VPC, ECS instances, an ALB instance, security groups, and automatic deployment configurations.
  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: Zone 1
  ZoneId2:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    AssociationPropertyMetadata:
      AutoSelectFirst: true
      ExclusiveTo:
        - ZoneId1
    Label:
      en: Availability Zone
      zh-cn: Zone 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: Instance Type 1
    Description:
      zh-cn: This solution creates a spot instance and automatically deploys the NGINX service.
      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: Instance Type 2
    Description:
      zh-cn: This solution creates a spot instance and automatically deploys the NGINX service.
      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: >-
        The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
    Label:
      en: Instance Password
      zh-cn: Instance Password
    ConstraintDescription:
      en: >-
        Length 8-30, must contain three(Capital letters, lowercase letters,
        numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
      zh-cn: 'The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
    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: The web endpoint.
      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:elastic-computing:Build a high-availability NGINX website
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Build a high-availability NGINX website across two zones. The template includes a VPC, ECS instances, an ALB instance, security groups, and automatic deployment configurations.",
    "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": "Zone 1"
      }
    },
    "ZoneId2": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "AssociationPropertyMetadata": {
        "AutoSelectFirst": true,
        "ExclusiveTo": [
          "ZoneId1"
        ]
      },
      "Label": {
        "en": "Availability Zone",
        "zh-cn": "Zone 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": "Instance Type 1"
      },
      "Description": {
        "zh-cn": "This solution creates a spot instance and automatically deploys the NGINX service.",
        "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": "Instance Type 2"
      },
      "Description": {
        "zh-cn": "This solution creates a spot instance and automatically deploys the NGINX service.",
        "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": "The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
      },
      "Label": {
        "en": "Instance Password",
        "zh-cn": "Instance Password"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
        "zh-cn": "The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
      },
      "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": "The web endpoint.",
        "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:elastic-computing:Build a high-availability NGINX website"
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}

For more examples, see public templates that contain this resource.