AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

Elastic Load Balancing 模板代码段

Elastic Load Balancing 负载均衡器资源

此示例显示的是带侦听程序和且不含实例的 Elastic Load Balancing 负载均衡器。

JSON

Copy
"MyLoadBalancer" : { "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "Listeners" : [ { "LoadBalancerPort" : "80", "InstancePort" : "80", "Protocol" : "HTTP" } ] } }

YAML

Copy
MyLoadBalancer: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: AvailabilityZones: - "us-east-1a" Listeners: - LoadBalancerPort: '80' InstancePort: '80' Protocol: HTTP

带运行状况检查的 Elastic Load Balancing 负载均衡器资源

此示例显示的是带两个 Amazon EC2 实例、一个侦听程序和一个运行状态检查的 Elastic Load Balancing 负载均衡器。

JSON

Copy
"MyLoadBalancer" : { "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "Instances" : [ { "Ref" : "logical name of AWS::EC2::Instance resource 1" }, { "Ref" : "logical name of AWS::EC2::Instance resource 2" } ], "Listeners" : [ { "LoadBalancerPort" : "80", "InstancePort" : "80", "Protocol" : "HTTP" } ], "HealthCheck" : { "Target" : "HTTP:80/", "HealthyThreshold" : "3", "UnhealthyThreshold" : "5", "Interval" : "30", "Timeout" : "5" } } }

YAML

Copy
MyLoadBalancer: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: AvailabilityZones: - "us-east-1a" Instances: - Ref: logical name of AWS::EC2::Instance resource 1 - Ref: logical name of AWS::EC2::Instance resource 2 Listeners: - LoadBalancerPort: '80' InstancePort: '80' Protocol: HTTP HealthCheck: Target: HTTP:80/ HealthyThreshold: '3' UnhealthyThreshold: '5' Interval: '30' Timeout: '5'