ALIYUN::ALB::Listener類型用於建立HTTP、HTTPS或QUIC監聽。
文法
{
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"RequestTimeout": Integer,
"ListenerPort": Integer,
"Http2Enabled": Boolean,
"DefaultActions": List,
"Certificates": List,
"IdleTimeout": Integer,
"LoadBalancerId": String,
"ListenerProtocol": String,
"QuicConfig": Map,
"GzipEnabled": Boolean,
"SecurityPolicyId": String,
"ListenerDescription": String,
"XForwardedForConfig": Map,
"CaEnabled": Boolean,
"CaCertificates": List,
"ListenerStatus": String,
"LogConfig": Map
}
}屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
DefaultActions | List | 是 | 是 | 規則動作列表。 | 取值樣本: 更多資訊,請參見DefaultActions屬性。 |
ListenerPort | Integer | 是 | 否 | 監聽連接埠。 | 取值範圍:1~65,535。 |
ListenerProtocol | String | 是 | 否 | 監聽協議。 | 取值:
|
LoadBalancerId | String | 是 | 否 | Server Load Balancer執行個體ID。 | 無 |
CaCertificates | List | 否 | 是 | CA認證資訊。 | 更多資訊,請參見CaCertificates屬性。 |
CaEnabled | Boolean | 否 | 是 | 是否開啟雙向認證。 | 取值:
|
Certificates | List | 否 | 是 | 認證。 | 更多資訊,請參見Certificates屬性。 |
GzipEnabled | Boolean | 否 | 是 | 是否開啟Gzip壓縮,壓縮特定檔案類型。 | 取值:
|
Http2Enabled | Boolean | 否 | 是 | 是否開啟HTTP/2特性。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
IdleTimeout | Integer | 否 | 是 | 串連空閑逾時時間。 | 取值範圍:1~60。 預設值:15。 單位:秒。 如果在逾時時間內一直沒有訪問請求,負載平衡會暫時中斷當前串連,直到下一次請求來臨時重建立立新的串連。 |
ListenerDescription | String | 否 | 是 | 監聽的描述資訊。 | 長度為2~256個字元。 |
ListenerStatus | String | 否 | 是 | 監聽的狀態。 | 取值:
|
LogConfig | Map | 否 | 是 | 日誌配置。 | 更多資訊,請參見LogConfig屬性。 |
QuicConfig | Map | 否 | 是 | 配置關聯的QUIC監聽。 | 更多資訊,請參見QuicConfig屬性。 |
RequestTimeout | Integer | 否 | 是 | 請求逾時時間。 | 取值範圍:1~180。 預設值:60。 單位:秒。 如果在逾時時間內後端伺服器一直沒有響應,負載平衡將放棄等待,並給用戶端返回HTTP 504錯誤碼。 |
SecurityPolicyId | String | 否 | 是 | 安全性原則ID。 | 支援系統安全性原則和自訂安全性原則。 預設值:tls_cipher_policy_1_0,表示系統安全性原則。 說明 僅HTTPS監聽支援此參數。 |
XForwardedForConfig | Map | 否 | 是 | XForward欄位配置資訊。 | 更多資訊,請參見XForwardedForConfig屬性。 |
DefaultActions文法
"DefaultActions": [
{
"Type": String,
"ForwardGroupConfig": Map
}
]DefaultActions屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
ForwardGroupConfig | Map | 是 | 是 | 轉寄Action對應的配置。 | 更多資訊,請參見ForwardGroupConfig屬性。 |
Type | String | 是 | 是 | 動作類型。 | 取值:ForwardGroup,表示轉寄至多個虛擬伺服器組。 |
ForwardGroupConfig文法
"ForwardGroupConfig": {
"ServerGroupTuples": List
}ForwardGroupConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
ServerGroupTuples | List | 是 | 是 | 轉寄目標伺服器組。 | 更多資訊,請參見ServerGroupTuples屬性。 |
ServerGroupTuples文法
"ServerGroupTuples": [
{
"ServerGroupId": String
}
]ServerGroupTuples屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
ServerGroupId | String | 是 | 是 | 轉寄到的目標伺服器組ID。 | 無 |
Certificates文法
"Certificates": [
{
"CertificateId": String
}
]Certificates屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
CertificateId | String | 否 | 是 | 認證ID。 | 當前僅支援伺服器憑證。 |
QuicConfig文法
"QuicConfig": {
"QuicListenerId": String,
"QuicUpgradeEnabled": Boolean
}QuicConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
QuicListenerId | String | 否 | 是 | 需要關聯的QUIC監聽ID。 | 當QuicUpgradeEnabled取值為true時必須指定該參數。 說明
|
QuicUpgradeEnabled | Boolean | 否 | 是 | 是否開啟QUIC升級。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
LogConfig文法
"LogConfig": {
"AccessLogTracingConfig": Map,
"AccessLogRecordCustomizedHeadersEnabled": Boolean
}LogConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
AccessLogTracingConfig | Map | 否 | 是 | 訪問日誌 Xtrace 相關的配置資訊。 | 更多資訊,請參見AccessLogTracingConfig屬性。 |
AccessLogRecordCustomizedHeadersEnabled | Boolean | 否 | 是 | 訪問日誌是否開啟攜帶自訂頭。 | 取值:
|
AccessLogTracingConfig文法
"AccessLogTracingConfig": {
"TracingSample": Integer,
"TracingType": String,
"TracingEnabled": Boolean
}AccessLogTracingConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
TracingEnabled | Boolean | 否 | 是 | 是否開啟 Xtrace 功能。 | 取值:
說明 只有執行個體訪問日誌開關 AccessLogEnabled 開啟時,才能將此參數設定為 true。 |
TracingSample | Integer | 否 | 是 | Xtrace 的採樣率。 | 取值:1~10000。 說明 TracingEnabled 為 true 時,此值有效。 |
TracingType | String | 否 | 是 | Xtrace 類型。 | 合法取值為 Zipkin。 說明 TracingEnabled 為 true 時,此值有效。 |
XForwardedForConfig文法
"XForwardedForConfig": {
"XForwardedForClientCertFingerprintAlias": String,
"XForwardedForClientCertFingerprintEnabled": Boolean,
"XForwardedForClientCertIssuerDNAlias": String,
"XForwardedForClientCertClientVerifyAlias": String,
"XForwardedForSLBIdEnabled": Boolean,
"XForwardedForClientCertSubjectDNEnabled": Boolean,
"XForwardedForClientCertSubjectDNAlias": String,
"XForwardedForProtoEnabled": Boolean,
"XForwardedForClientSrcPortEnabled": Boolean,
"XForwardedForSLBPortEnabled": Boolean,
"XForwardedForEnabled": Boolean,
"XForwardedForClientCertIssuerDNEnabled": Boolean,
"XForwardedForClientCertClientVerifyEnabled": Boolean,
"XForwardedForClientSourceIpsEnabled": Boolean,
"XForwardedForClientSourceIpsTrusted": String,
"XForwardedForProcessingMode": String,
"XForwardedForHostEnabled": Boolean
}XForwardedForConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
XForwardedForClientCertClientVerifyAlias | String | 否 | 是 | 自訂頭名稱,用於擷取對訪問Server Load Balancer執行個體用戶端認證的校正結果。 | 當XForwardedForClientCertClientVerifyEnabled取值為true時,該參數有效。 長度為1~40個字元,可包含小寫英文字母、數字、短劃線(-)和底線(_)。 說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertClientVerifyEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Clientcert-clientverify頭欄位擷取對訪問Server Load Balancer執行個體用戶端認證的校正結果。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertFingerprintAlias | String | 否 | 是 | 自訂頭名稱,用於擷取訪問Server Load Balancer執行個體用戶端認證的指紋取值。 | 當XForwardedForClientCertFingerprintEnabled取值為true時,該參數有效。 長度為1~40個字元,可包含小寫英文字母、數字、短劃線(-)和底線(_)。 說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertFingerprintEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Clientcert-fingerprint頭欄位擷取訪問Server Load Balancer執行個體用戶端認證的指紋取值。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertIssuerDNAlias | String | 否 | 是 | 自訂頭名稱,用於擷取訪問Server Load Balancer執行個體用戶端認證的發行者資訊。 | 當XForwardedForClientCertIssuerDNEnabled取值為true時,該參數有效。 長度為1~40個字元,可包含小寫英文字母、數字、短劃線(-)和底線(_)。 說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertIssuerDNEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Clientcert-issuerdn頭欄位擷取訪問Server Load Balancer執行個體用戶端認證的發行者資訊。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertSubjectDNAlias | String | 否 | 是 | 自訂頭名稱,用於擷取訪問Server Load Balancer執行個體用戶端認證的所有者資訊。 | 當XForwardedForClientCertSubjectDNEnabled取值為true時,該參數有效。 長度為1~40個字元,可包含小寫英文字母、數字、短劃線(-)和底線(_)。 說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientCertSubjectDNEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Clientcert-subjectdn頭欄位擷取訪問Server Load Balancer執行個體用戶端認證的所有者資訊。 | 取值:
說明 僅HTTPS監聽支援指定該參數。 |
XForwardedForClientSourceIpsEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Client-SourceIps頭欄位擷取訪問Server Load Balancer執行個體用戶端的源連接埠。 | 取值:
|
XForwardedForClientSourceIpsTrusted | String | 否 | 是 | 指定可信的代理 IP。 | 應用型負載平衡 ALB 會從後往前遍曆 |
XForwardedForClientSrcPortEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Client-Port頭欄位擷取訪問Server Load Balancer執行個體用戶端的連接埠。 | 取值:
說明 僅HTTP和HTTPS監聽支援指定該參數。 |
XForwardedForEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-For頭欄位擷取來訪者真實IP地址。 | 取值:
說明 僅HTTP和HTTPS監聽支援指定該參數。 |
XForwardedForHostEnabled | Boolean | 否 | 是 | 是否開啟通過 | 取值:
說明 HTTP、HTTPS 和 QUIC 監聽支援此參數。 |
XForwardedForProcessingMode | String | 否 | 是 | 處理 | 只有當 XForwardedForEnabled 為 true 時,此值才會生效。取值:
說明
|
XForwardedForProtoEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Proto頭欄位擷取Server Load Balancer執行個體的監聽協議。 | 取值:
|
XForwardedForSLBIdEnabled | Boolean | 否 | 是 | 是否通過SLB-ID頭欄位擷取Server Load Balancer執行個體ID。 | 取值:
|
XForwardedForSLBPortEnabled | Boolean | 否 | 是 | 是否通過X-Forwarded-Port頭欄位擷取Server Load Balancer執行個體的監聽連接埠。 | 取值:
|
CaCertificates文法
"CaCertificates": [
{
"CertificateId": String
}
]CaCertificates屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
CertificateId | String | 否 | 是 | CA認證ID。 | 無 |
傳回值
Fn::GetAtt
ListenerId:監聽ID。
LoadBalancerId:應用型Server Load Balancer執行個體 ID。
樣本
情境 1 :建立HTTP監聽。
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
LoadBalancerId:
Type: String
Description: The ID of the ALB instance.
Default: lb-bp1iilcd9ujny84z8****
Resources:
Listener:
Type: ALIYUN::ALB::Listener
Properties:
ListenerPort: 80
DefaultActions:
- ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId: sgp-46ndzg2wz4v5mp****
Type: ForwardGroup
LoadBalancerId:
Ref: LoadBalancerId
ListenerProtocol: HTTP
Outputs:
ListenerId:
Description: The ID of the listener.
Value:
Fn::GetAtt:
- Listener
- ListenerId {
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"LoadBalancerId": {
"Type": "String",
"Description": "The ID of the ALB instance.",
"Default": "lb-bp1iilcd9ujny84z8****"
}
},
"Resources": {
"Listener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": "sgp-46ndzg2wz4v5mp****"
}
]
},
"Type": "ForwardGroup"
}
],
"LoadBalancerId": {
"Ref": "LoadBalancerId"
},
"ListenerProtocol": "HTTP"
}
}
},
"Outputs": {
"ListenerId": {
"Description": "The ID of the listener.",
"Value": {
"Fn::GetAtt": [
"Listener",
"ListenerId"
]
}
}
}
}情境 2 :建立雙可用性區域ALB負載平衡,並建立HTTP監聽。
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 建立雙可用性區域ALB負載平衡。
en: Create a dual-Availability-Zone ALB.
Parameters:
CommonName:
Type: String
Default: elastic-app
ZoneId1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId2
Label:
en: Availability Zone
zh-cn: 可用性區域1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: 可用性區域2
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
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
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: Alb
ListenerProtocol: HTTP
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId1
- ZoneId2
Hidden:
- CommonName
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"zh-cn": "建立雙可用性區域ALB負載平衡。",
"en": "Create a dual-Availability-Zone ALB."
},
"Parameters": {
"CommonName": {
"Type": "String",
"Default": "elastic-app"
},
"ZoneId1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"ExclusiveTo": [
"ZoneId2"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域2"
}
}
},
"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"
}
}
},
"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
}
}
},
"AlbListener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"Type": "ForwardGroup",
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": {
"Ref": "AlbServerGroup"
}
}
]
}
}
],
"LoadBalancerId": {
"Ref": "Alb"
},
"ListenerProtocol": "HTTP"
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ZoneId1",
"ZoneId2"
]
}
],
"Hidden": [
"CommonName"
]
}
}
}情境 3 :搭建高可用的 nginx 網站。
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。
en: Establish a dual-Availability Zone high-availability NGINX website, encompassing
a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application
Load Balancer (ALB), Security Groups, and automated deployment configurations.
Parameters:
CommonName:
Type: String
Default: elastic-app
ZoneId1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- ZoneId2
Label:
en: Availability Zone
zh-cn: 可用性區域1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: 可用性區域2
InstanceType1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
SpotStrategy: SpotAsPriceGo
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格1
Description:
zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
en: >-
This solution will create a spot instance and automatically deploy a
nginx service.
Default: null
InstanceType2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
SpotStrategy: SpotAsPriceGo
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格2
Description:
zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
en: >-
This solution will create a spot instance and automatically deploy a
nginx service.
Default: null
InstancePassword:
NoEcho: true
Type: String
Description:
en: >-
Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
symbol in)
zh-cn: >-
伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符號)
Label:
en: Instance Password
zh-cn: 執行個體密碼
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: '長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符號)'
AssociationProperty: 'ALIYUN::ECS::Instance::Password'
Default: null
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: ${CommonName}-vpc
VSwitch1:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch2:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.2.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-vsw
SecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
EcsInstance1:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs-1
InstanceType:
Ref: InstanceType1
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
SpotStrategy: SpotAsPriceGo
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
EcsInstance2:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs-2
InstanceType:
Ref: InstanceType2
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
SpotStrategy: SpotAsPriceGo
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
Alb:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
VpcId:
Ref: Vpc
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
ZoneMappings:
- ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
- ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
AlbServerGroup:
Type: 'ALIYUN::ALB::ServerGroup'
Properties:
VpcId:
Ref: Vpc
ServerGroupType: Instance
ServerGroupName:
Fn::Sub: ${CommonName}-server-group
HealthCheckConfig:
HealthCheckConnectPort: 80
HealthCheckCodes:
- http_2xx
- http_3xx
HealthCheckProtocol: HTTP
HealthCheckEnabled: true
HealthCheckPath: /
StickySessionConfig:
StickySessionEnabled: false
AlbBackendServerAttachment:
Type: 'ALIYUN::ALB::BackendServerAttachment'
Properties:
ServerGroupId:
Ref: AlbServerGroup
Servers:
- ServerType: Ecs
ServerId:
Ref: EcsInstance1
Port: 80
- ServerType: Ecs
ServerId:
Ref: EcsInstance2
Port: 80
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: Alb
ListenerProtocol: HTTP
Outputs:
WebUrl:
Description:
zh-cn: Web 存取地址。
en: The Addresses of Web.
Value:
'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId1
- InstanceType1
- ZoneId2
- InstanceType2
- InstancePassword
TemplateTags:
- acs:example:彈性計算:搭建高可用的 nginx 網站
Hidden:
- CommonName
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"zh-cn": "建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。",
"en": "Establish a dual-Availability Zone high-availability NGINX website, encompassing a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application Load Balancer (ALB), Security Groups, and automated deployment configurations."
},
"Parameters": {
"CommonName": {
"Type": "String",
"Default": "elastic-app"
},
"ZoneId1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"AutoSelectFirst": true,
"ExclusiveTo": [
"ZoneId2"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"AutoSelectFirst": true,
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域2"
}
},
"InstanceType1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"SpotStrategy": "SpotAsPriceGo",
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格1"
},
"Description": {
"zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
"en": "This solution will create a spot instance and automatically deploy a nginx service."
},
"Default": null
},
"InstanceType2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"SpotStrategy": "SpotAsPriceGo",
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格2"
},
"Description": {
"zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
"en": "This solution will create a spot instance and automatically deploy a nginx service."
},
"Default": null
},
"InstancePassword": {
"NoEcho": true,
"Type": "String",
"Description": {
"en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
"zh-cn": "伺服器登入密碼,長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"Label": {
"en": "Instance Password",
"zh-cn": "執行個體密碼"
},
"ConstraintDescription": {
"en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
"zh-cn": "長度8-30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"AssociationProperty": "ALIYUN::ECS::Instance::Password",
"Default": null
}
},
"Resources": {
"Vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "192.168.0.0/16",
"VpcName": {
"Fn::Sub": "${CommonName}-vpc"
}
}
},
"VSwitch1": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.1.0/24",
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"VSwitch2": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.2.0/24",
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"SecurityGroupName": {
"Fn::Sub": "${CommonName}-sg"
},
"SecurityGroupIngress": [
{
"PortRange": "443/443",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
},
{
"PortRange": "80/80",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
}
]
}
},
"EcsInstance1": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-1"
},
"InstanceType": {
"Ref": "InstanceType1"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"SpotStrategy": "SpotAsPriceGo",
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"EcsInstance2": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-2"
},
"InstanceType": {
"Ref": "InstanceType2"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"SpotStrategy": "SpotAsPriceGo",
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"Alb": {
"Type": "ALIYUN::ALB::LoadBalancer",
"Properties": {
"LoadBalancerName": {
"Fn::Sub": "${CommonName}-alb"
},
"LoadBalancerEdition": "Basic",
"VpcId": {
"Ref": "Vpc"
},
"LoadBalancerBillingConfig": {
"PayType": "PostPay"
},
"AddressType": "Internet",
"ZoneMappings": [
{
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
}
},
{
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
}
}
]
}
},
"AlbServerGroup": {
"Type": "ALIYUN::ALB::ServerGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ServerGroupType": "Instance",
"ServerGroupName": {
"Fn::Sub": "${CommonName}-server-group"
},
"HealthCheckConfig": {
"HealthCheckConnectPort": 80,
"HealthCheckCodes": [
"http_2xx",
"http_3xx"
],
"HealthCheckProtocol": "HTTP",
"HealthCheckEnabled": true,
"HealthCheckPath": "/"
},
"StickySessionConfig": {
"StickySessionEnabled": false
}
}
},
"AlbBackendServerAttachment": {
"Type": "ALIYUN::ALB::BackendServerAttachment",
"Properties": {
"ServerGroupId": {
"Ref": "AlbServerGroup"
},
"Servers": [
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance1"
},
"Port": 80
},
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance2"
},
"Port": 80
}
]
}
},
"AlbListener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"Type": "ForwardGroup",
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": {
"Ref": "AlbServerGroup"
}
}
]
}
}
],
"LoadBalancerId": {
"Ref": "Alb"
},
"ListenerProtocol": "HTTP"
}
}
},
"Outputs": {
"WebUrl": {
"Description": {
"zh-cn": "Web 存取地址。",
"en": "The Addresses of Web."
},
"Value": {
"Fn::Sub": "http://${Alb.DNSName}"
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ZoneId1",
"InstanceType1",
"ZoneId2",
"InstanceType2",
"InstancePassword"
]
}
],
"TemplateTags": [
"acs:example:彈性計算:搭建高可用的 nginx 網站"
],
"Hidden": [
"CommonName"
]
}
}
}更多樣本,請參考包含此資源的公用模板。