Tous les produits
Search
Centre de documentation

Resource Orchestration Service:ALIYUN::ALB::LoadBalancer

Dernière mise à jour :Aug 10, 2026

Crée une instance Application Load Balancer (ALB).

Syntaxe

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

Propriétés

Nom de la propriété

Type

Obligatoire

Mise à jour autorisée

Description

Contraintes

AddressType

String

Oui

Non

Le type d'adresse de l'instance ALB.

Valeurs valides :

  • Internet : adresse IP publique.

    Étant donné que le nom de domaine DNS pointe vers une adresse IP publique, l'instance est accessible depuis le réseau public.

  • Intranet : adresse IP privée.

    L'instance ALB utilise une adresse IP privée. Le nom de domaine est résolu vers l'adresse IP privée et l'instance n'est accessible qu'au sein de son VPC (Virtual Private Cloud).

LoadBalancerBillingConfig

Map

Oui

Non

La configuration de facturation.

Pour plus d'informations, consultez les propriétés LoadBalancerBillingConfig.

LoadBalancerEdition

String

Oui

Oui

L'édition de l'instance ALB.

Valeurs valides :

  • Basic : édition Basic.

  • Standard : édition Standard

  • StandardWithWaf : WAF activé

VpcId

String

Oui

Non

L'ID du VPC.

Aucune

ZoneMappings

List

Oui

Non

La liste des zones et des vSwitch.

Vous devez spécifier au moins deux zones. Pour plus d'informations, consultez les propriétés ZoneMappings.

AccessLogConfig

Map

Non

Oui

La configuration des journaux d'accès.

Pour plus d'informations, consultez les propriétés AccessLogConfig.

AddressAllocatedMode

String

Non

Non

Le mode d'allocation des adresses.

Valeurs valides :

  • Fixed : une adresse IP statique est utilisée.

  • Dynamic (par défaut) : une adresse IP est attribuée dynamiquement à chaque zone.

AddressIpVersion

String

Non

Non

La version IP de l'instance ALB.

Valeurs valides :

  • IPv4 : Internet Protocol version 4.

  • DualStack : double pile

BandwidthPackageId

String

Non

Oui

L'ID de l'instance Internet Shared Bandwidth associée à l'instance ALB.

Ce paramètre n'est valide que si AddressType est défini sur Internet.

DeletionProtectionEnabled

Boolean

Non

Oui

Indique si la protection contre la suppression est activée.

Valeurs valides :

  • true : la protection contre la suppression est activée.

  • false (par défaut) : la protection contre la suppression est désactivée.

Ipv6AddressType

String

Non

Oui

Le type d'adresse IPv6 de l'instance ALB.

Valeurs valides : Internet : l'instance ALB utilise une adresse IPv6 publique. Le nom de domaine de l'instance ALB est résolu vers l'adresse IPv6 publique. Intranet : l'instance ALB utilise une adresse IPv6 privée. Le nom de domaine de l'instance ALB est résolu vers l'adresse IP privée.

LoadBalancerName

String

Non

Oui

Le nom de l'instance ALB.

Le nom doit comporter entre 1 et 80 caractères. Il peut contenir des lettres, des chiffres, des traits d'union (-), des barres obliques (/), des points (.) et des traits de soulignement (_).

Si vous ne spécifiez pas ce paramètre, le système attribue automatiquement un nom à l'instance.

ModificationProtectionConfig

Map

Non

Oui

La configuration de protection contre les modifications.

Pour plus d'informations, consultez les propriétés ModificationProtectionConfig.

ResourceGroupId

String

Non

Oui

L'ID du groupe de ressources.

Aucune

SecurityGroupIds

List

Non

Oui

Les ID des groupes de sécurité associés à l'instance ALB.

La fonctionnalité de groupe de sécurité n'est pas activée par défaut. Pour utiliser cette fonctionnalité, contactez votre gestionnaire de compte.

Tags

List

Non

Oui

Les tags de l'instance ALB.

Vous pouvez ajouter jusqu'à 20 tags.

Pour plus d'informations, consultez les propriétés Tags.

Syntaxe AccessLogConfig

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

Propriétés AccessLogConfig

Nom de la propriété

Type

Obligatoire

Mise à jour autorisée

Description

Contraintes

LogProject

String

Oui

Non

Le projet de journalisation.

Aucune

LogStore

String

Oui

Non

Le Logstore.

Aucune

Enable

Boolean

Non

Oui

Indique si la fonctionnalité de journal des accès est activée.

Valeurs valides :

  • true : active la fonctionnalité de journal des accès.

  • false : désactive la fonctionnalité de journal des accès.

Syntaxe LoadBalancerBillingConfig

"LoadBalancerBillingConfig": {
  "PayType": String
}

Propriétés LoadBalancerBillingConfig

Nom de la propriété

Type

Obligatoire

Mise à jour autorisée

Description

Contraintes

PayType

String

Oui

Non

La méthode de facturation de l'instance ALB.

Valeur valide : PostPay. Cette valeur spécifie la méthode de facturation au paiement à l'utilisation.

Syntaxe ZoneMappings

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

Propriétés de ZoneMappings

Property Name

Type

Required

Update allowed

Description

Constraints

VSwitchId

String

Yes

No

L'ID du vSwitch.

Chaque zone ne peut contenir qu'un seul vSwitch.

ZoneId

String

Yes

No

L'ID de la zone.

Aucun

AllocationId

String

No

No

L'ID de l'adresse IP élastique (EIP) associée à l'instance ALB.

Aucun

EipType

String

No

No

Le type d'EIP public.

Valeurs valides :

  • Common : Elastic IP Address (EIP).

  • Anycast : une EIP anycast.

Remarque

Pour plus d'informations sur les régions où ALB prend en charge les EIP Anycast, consultez Associate an Anycast EIP with an ALB instance to accelerate access across regions.

LoadBalancerAddresses

List

No

No

Les adresses de l'instance ALB.

Pour plus d'informations, consultez Propriétés LoadBalancerAddresses.

IntranetAddress

String

No

No

L'adresse IPv4 privée.

Aucun

Syntaxe LoadBalancerAddresses

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

Propriétés LoadBalancerAddresses

Property Name

Type

Required

Update allowed

Description

Constraints

AllocationId

String

Yes

No

L'ID de l'EIP associée à l'instance ALB.

Aucun

EipType

String

No

No

Le type d'EIP public.

Valeurs valides :

  • Common : une EIP.

  • Anycast : une EIP anycast.

Remarque

Pour plus d'informations sur les régions où ALB prend en charge les EIP Anycast, consultez Associate an Anycast EIP with an ALB instance to accelerate access across regions.

IntranetAddress

String

No

No

L'adresse IPv4 privée.

Aucun

Syntaxe ModificationProtectionConfig

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

Propriétés ModificationProtectionConfig

Property Name

Type

Required

Update allowed

Description

Constraints

Status

String

Yes

Yes

L'état de la protection contre la modification.

Valeurs valides :

  • NonProtection : La protection contre la modification n'est pas activée. Vous ne pouvez pas spécifier le paramètre Reason.

  • ConsoleProtection : La protection contre la modification est activée dans la console. Vous pouvez spécifier le paramètre Reason.

Reason

String

No

Yes

La raison de l'activation de la protection contre la modification.

La chaîne doit comporter entre 2 et 128 caractères, commencer par une lettre anglaise ou un caractère chinois, et ne contenir que des lettres anglaises, des caractères chinois, des chiffres, des points (.), des traits de soulignement (_) et des tirets (-).

Remarque

Ce paramètre n'est valide que lorsque Status est défini sur ConsoleProtection.

Syntaxe Tags

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

Propriétés Tags

Property Name

Type

Required

Update allowed

Description

Constraints

Key

String

Yes

No

La clé du tag.

La clé du tag doit comporter entre 1 et 128 caractères. Elle ne peut pas commencer par aliyun ou acs: et ne peut pas contenir http:// ou https://.

Value

String

No

No

La valeur du tag.

La valeur du tag doit comporter entre 0 et 128 caractères. Elle ne peut pas commencer par aliyun ou acs: et ne peut pas contenir http:// ou https://.

Valeurs de retour

Fn::GetAtt

  • LoadBalancerEdition : L'édition de l'instance ALB.

  • VpcId : L'ID du VPC.

  • LoadBalancerId : L'ID de l'instance ALB.

  • AddressType : Le type d'adresse de l'instance ALB.

  • DNSName : Le nom de domaine de l'instance ALB.

  • ZoneMappings : La liste des zones et des vSwitches.

  • Arn : Le nom de ressource Alibaba Cloud (ARN) de la ressource.

Exemples

Scénario 1 : instance Application Load Balancer (ALB).

Création rapide

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

Scénario 2 : Créez une instance ALB dans deux zones de disponibilité avec ESS pour la mise à l'échelle automatique

Création rapide

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

Scénario 3 : Déployer un site web NGINX haute disponibilité.

Création rapide

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

Pour plus d'exemples, consultez les modèles publics contenant cette ressource.