云形成应用程序负载均衡器弹性 IP 错误



我正在尝试使用 Cloudformation 自动化一个由一个 Fargate 集群、多个服务和一个应用程序负载均衡器组成的堆栈。

遗憾的是,负载均衡器的创建失败,并显示以下错误消息:"类型为'应用程序'的负载均衡器不支持弹性 IP"

我知道不支持弹性 IP,但我无法弄清楚为什么 Cloudformation 尝试为我的负载均衡器分配弹性 IP。我在参考中没有发现有关某些值默认为弹性 IP 分配的提示。

"Resources": {
"Cluster": {
"Type": "AWS::ECS::Cluster",
"Properties": {}
},
"Service": {
"Type": "AWS::ECS::Service",
"Properties": {
"Cluster": {
"Ref": "Cluster"
},
"TaskDefinition": {
"Ref": "Task"
},
"LoadBalancers": [
{
"ContainerName": "service1",
"ContainerPort": 80,
"LoadBalancerName": {
"Ref": "LoadBalancer"
},
"TargetGroupArn": {
"Ref": "TargetGroup"
}
}
],
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "false",
"Subnets": [
{
"Ref": "Subnet1"
},
{
"Ref": "Subnet2"
}
]
}
}
}
},
"Task": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [
{
"PortMappings": [
{
"HostPort": 80,
"Protocol": "tcp",
"ContainerPort": 80
}
],
"Environment": [
{
"Name": "SERVER_PORT",
"Value": "80"
}
],
"Image": "arn",
"Essential": true,
"Name": "service1",
"Memory": 2048
}
],
"TaskRoleArn": "arn",
"NetworkMode": "awsvpc"
}
},
"LoadBalancer": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"SubnetMappings": [
{
"SubnetId": {
"Ref": "Subnet1"
},
"AllocationId": "subnet-1"
},
{
"SubnetId": {
"Ref": "Subnet2"
},
"AllocationId": "subnet-2"
}
],
"SecurityGroups": [
{
"Ref": "VPCSecurityGroup"
}
]
}
},
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
},
"VPCSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"GroupDescription": "security group"
}
},
"Subnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.0.0/24",
"MapPublicIpOnLaunch": false
}
},
"Subnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.1.0/24",
"MapPublicIpOnLaunch": false
}
},
"Listener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"LoadBalancerArn": {
"Ref": "LoadBalancer"
},
"DefaultActions": [
{
"Type": "FORWARD"
}
],
"Port": 443,
"Protocol": "HTTPS",
"Certificates": [
{
"CertificateArn": "arn"
}
]
}
},
"TargetGroup": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Port": 80,
"Protocol": "HTTP"
}
},
"ListenerRule": {
"Type": "AWS::ElasticLoadBalancingV2::ListenerRule",
"Properties": {
"Actions": [
{
"Type": "FORWARD"
}
],
"Priority": 1,
"Conditions": [],
"ListenerArn": {
"Ref": "Listener"
}
}
}

我通过删除子网映射属性并声明子网属性来修复弹性 IP 错误。

"LoadBalancer": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"Subnets": [
{
"Ref": "PublicSubnet1"
},
{
"Ref": "PublicSubnet2"
}
],
"SecurityGroups": [
{
"Ref": "VPCSecurityGroup"
}
]
}
}

最新更新