EC2 实例与 ELB 不在同一个 VPC 中。无效实例
EC2 instance is not in the same VPC as ELB. Invalid Instance
使用 AWS CloudFormation 服务,我尝试在 2 个 EC2 实例上创建弹性负载均衡器,但出现错误:
EC2 instance i-0a38204c18b48604c is not in the same VPC as ELB. (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidInstance; Request ID: 2af5dc7e-9a7f-11e8-91c9-a3410fab05ba)".
正在正确创建 EC2 实例,但未创建 ELB。我该如何解决这个问题?
请找到完整代码以供参考here
ElasticLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
AvailabilityZones:
- 'us-east-2a'
Instances: [!Ref 'webServer1', !Ref 'webServer2']
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
HealthCheck:
Target: HTTP:80/
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '30'
Timeout: '5'
您还没有为您的 ELB 指定任何 Subnets
。因此,ELB是在默认的VPC中创建的。
VPC -- contains --> Subnets -- contains --> ELB
将 Subnets
parameter 添加到您的 ELB:
Subnets:
A list of subnet IDs in your virtual private cloud (VPC) to attach to your load balancer. Do not specify multiple subnets that are in the same Availability Zone. You can specify the AvailabilityZones
or Subnets
property, but not both.
使用 AWS CloudFormation 服务,我尝试在 2 个 EC2 实例上创建弹性负载均衡器,但出现错误:
EC2 instance i-0a38204c18b48604c is not in the same VPC as ELB. (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidInstance; Request ID: 2af5dc7e-9a7f-11e8-91c9-a3410fab05ba)".
正在正确创建 EC2 实例,但未创建 ELB。我该如何解决这个问题?
请找到完整代码以供参考here
ElasticLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
AvailabilityZones:
- 'us-east-2a'
Instances: [!Ref 'webServer1', !Ref 'webServer2']
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
HealthCheck:
Target: HTTP:80/
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '30'
Timeout: '5'
您还没有为您的 ELB 指定任何 Subnets
。因此,ELB是在默认的VPC中创建的。
VPC -- contains --> Subnets -- contains --> ELB
将 Subnets
parameter 添加到您的 ELB:
Subnets: A list of subnet IDs in your virtual private cloud (VPC) to attach to your load balancer. Do not specify multiple subnets that are in the same Availability Zone. You can specify the
AvailabilityZones
orSubnets
property, but not both.