CloudFormation AutoscalingGroup“LoadBalancer附件没有稳定”

时间:2017-02-07 20:59:46

标签: amazon-web-services amazon-cloudformation amazon-elb autoscaling

所以我使用ECS(通过ecs-cli创建)和CloudFormation,我在创建自动缩放组时遇到问题: Attachments did not stabilize

始终没有说“LoadBalancer附件没有稳定”。有谁知道是什么导致了这个?

我有两个CloudFormation堆栈,一个主要用于设置我的大部分基础架构,另一个用于第二个ECS群集(失败)。我从第一个/主堆栈的输出传递输入参数。

我想也许是子网大小问题(它们是在第一个堆栈中创建的,然后传递给第二个,10.0.0.0 / 24和10.0.1.0/24),所以我尝试创建两个新的子网第二个cloudformation模板并使用它们,但它导致了同样的错误。

两个模板文件之间的Autoscaling组和ELB创建相同...

FIRST STACK:

"InternetGateway": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::InternetGateway"
    },
    "AttachGateway": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::VPCGatewayAttachment",
        "Properties": {
            "VpcId": {
                "Ref": "Vpc"
            },
            "InternetGatewayId": {
                "Ref": "InternetGateway"
            }
        }
    },
    "RouteViaIgw": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::RouteTable",
        "Properties": {
            "VpcId": {
                "Ref": "Vpc"
            }
        }
    },
    "PublicRouteViaIgw": {
        "Condition": "CreateVpcResources",
        "DependsOn": "AttachGateway",
        "Type": "AWS::EC2::Route",
        "Properties": {
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            },
            "DestinationCidrBlock": "0.0.0.0/0",
            "GatewayId": {
                "Ref": "InternetGateway"
            }
        }
    },
    "PubSubnet1RouteTableAssociation": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::SubnetRouteTableAssociation",
        "Properties": {
            "SubnetId": {
                "Ref": "PubSubnetAz1"
            },
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            }
        }
    },
    "PubSubnet2RouteTableAssociation": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::SubnetRouteTableAssociation",
        "Properties": {
            "SubnetId": {
                "Ref": "PubSubnetAz2"
            },
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            }
        }
    },
"Outputs": {
    "VpcId": {
        "Value": { "Ref": "Vpc" }
    },
    "KeyName": {
        "Value": { "Ref": "KeyName" }
    },
    "SourceCidr": {
        "Value": { "Ref": "SourceCidr"}
    },
    "EcsInstancePolicy": {
        "Value": { "Ref": "EcsInstancePolicy" }
    },
    "SubnetIds": {
        "Value": { 
            "Fn::Join": [
                ",", [{
                        "Ref": "PubSubnetAz1"
                    },
                    {
                        "Ref": "PubSubnetAz2"
                    }
                ]
            ]
        }
    },
    "CloudSecurityGroup": {
        "Value": { "Ref": "EcsSecurityGroup" }
    },
    "GatewayRouteTable": {
        "Value": { "Ref": "PublicRouteViaIgw" }
    }
}

第二堆:

"Parameters": {
    "EcsAmiId": {
        "Type": "String",
        "Description": "ECS EC2 AMI id",
        "Default": ""
    },
    "EcsInstanceType": {
        "Type": "String",
        "Description": "ECS EC2 instance type",
        "ConstraintDescription": "must be a valid EC2 instance type."
    },
    "KeyName": {
        "Type": "AWS::EC2::KeyPair::KeyName",
        "Description": "Required - Name of an existing EC2 KeyPair to enable SSH access to the ECS instances"
    },
    "VpcId": {
        "Type": "String",
        "Description": "Required - VPC Id of existing VPC of Central stack.",
        "AllowedPattern": "^(?:vpc-[0-9a-f]{8}|)$",
        "ConstraintDescription": "VPC Id must begin with 'vpc-'"
    },
    "SubnetIds": {
        "Type": "String",
        "Description": "Required - Comma separated list of two (2) existing VPC Subnet Ids where ECS instances will run."
    },
    "AsgMaxSize": {
        "Type": "Number",
        "Description": "Maximum size and initial Desired Capacity of ECS Auto Scaling Group",
        "Default": "1"
    },
    "SourceCidr": {
        "Type": "String",
        "Description": "Required - Input CIDR/IP range to open up for ECS and Aurora"
    },
    "EcsInstancePolicy": {
        "Type": "String",
        "Description": "Required - IAM Policy for the ECS instances to use"
    },
    "EcsCluster": {
        "Type": "String",
        "Description": "ECS Cluster Name",
        "Default": "default"
    },
    "CloudSecurityGroup": {
        "Type": "String",
        "Description": "Name of the security group used by the ECS instances in the Cloud cluster"
    },
},
"Resources": {
    "EcsSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription": "ECS Allowed Ports",
            "VpcId": { "Ref": "VpcId" },
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "tcp",
                    "FromPort": 22,
                    "ToPort": 22,
                    "SourceSecurityGroupId": { "Ref": "CloudSecurityGroup" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 11000,
                    "ToPort": 11001,
                    "SourceSecurityGroupId": { "Ref": "CloudSecurityGroup" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 22,
                    "ToPort": 22,
                    "CidrIp": { "Ref": "SourceCidr" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 11000,
                    "ToPort": 11001,
                    "CidrIp": { "Ref": "SourceCidr" }
                }
            ]
        }
    },
    "EcsSecurityGroupIngressSelf": {
        "Type": "AWS::EC2::SecurityGroupIngress",
        "Properties": {
            "GroupId": { "Ref": "EcsSecurityGroup" },
            "SourceSecurityGroupId": { "Ref": "EcsSecurityGroup" },
            "IpProtocol": "tcp",
            "FromPort": 22,
            "ToPort": 9999
        }
    },
    "ElasticLoadBalancer": {
        "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
        "Properties": {
            "Subnets": {
                "Fn::Split": [
                    ",",
                    { "Ref": "SubnetIds" }
                ]
            },
            "CrossZone": "true",
            "SecurityGroups": [{
                "Ref": "EcsSecurityGroup"
            }],
            "Listeners": [{
                    "LoadBalancerPort": "22",
                    "InstancePort": "22",
                    "Protocol": "TCP"
                },
                {
                    "LoadBalancerPort": "11000",
                    "InstancePort": "11000",
                    "Protocol": "TCP"
                },
                {
                    "LoadBalancerPort": "11001",
                    "InstancePort": "11001",
                    "Protocol": "TCP"
                }
            ],
            "HealthCheck": {
                "HealthyThreshold": "2",
                "Interval": "30",
                "Target": "TCP:22",
                "Timeout": "5",
                "UnhealthyThreshold": "5"
            }
        }
    },
    "EcsInstanceProfile": {
        "Type": "AWS::IAM::InstanceProfile",
        "Properties": {
            "Path": "/",
            "Roles": [{
                "Ref": "EcsInstancePolicy"
            }]
        }
    },
    "EcsInstanceLc": {
        "Type": "AWS::AutoScaling::LaunchConfiguration",
        "Properties": {
            "ImageId": {
                "Ref": "EcsAmiId"
            },
            "InstanceType": {
                "Ref": "EcsInstanceType"
            },
            "AssociatePublicIpAddress": true,
            "IamInstanceProfile": {
                "Ref": "EcsInstanceProfile"
            },
            "KeyName": {
                "Ref": "KeyName"
            },
            "SecurityGroups": [{
                "Ref": "EcsSecurityGroup"
            }],
            "UserData": {
                "Fn::Base64": {
                    "Fn::Join": [
                        "", [
                            "#!/bin/bash\n",
                            "echo ECS_CLUSTER=",
                            {
                                "Ref": "EcsCluster"
                            },
                            " >> /etc/ecs/ecs.config\n"
                        ]
                    ]
                }
            }
        }
    },
    "EcsInstanceAsg": {
        "Type": "AWS::AutoScaling::AutoScalingGroup",
        "Properties": {
            "VPCZoneIdentifier": [{ "Ref": "SubnetIds" }],
            "LaunchConfigurationName": {
                "Ref": "EcsInstanceLc"
            },
            "MinSize": "1",
            "MaxSize": {
                "Ref": "AsgMaxSize"
            },
            "DesiredCapacity": {
                "Ref": "AsgMaxSize"
            },
            "LoadBalancerNames": [{ "Ref": "ElasticLoadBalancer" }],
            "Tags": [{
                "Key": "Name",
                "Value": {
                    "Fn::Join": [
                        "", [
                            "ECS Instance - ",
                            {
                                "Ref": "AWS::StackName"
                            }
                        ]
                    ]
                },
                "PropagateAtLaunch": "true"
            }]
        }
    },

如果有任何额外信息有帮助,请告诉我

2 个答案:

答案 0 :(得分:4)

从屏幕截图中看来,CloudFormation堆栈以及EcsInstanceAsg Auto Scaling组以前是创建过的,并且您正在尝试更新Auto Scaling组以引用新创建的Load Balancer。

CloudFormation资源在更新时无法稳定的最常见问题是由于在CloudFormation堆栈之外修改和/或删除了引用的资源。这会导致CloudFormation修改无法再找到的资源,这会导致随机错误或超时,并且根据AWS CloudFormation Best Practices不鼓励使用。如果是这种情况,最好的方法是尽可能使用全新的堆栈重新开始。

如果您不是这种情况,AWS::AutoScaling::AutoScalingGroupLoadBalancerNames属性的就地更新可能存在未知限制或问题(支持此属性的就地更新)仅为just added on Jan 17 2017,因此可能仍存在问题)。尝试重新创建Auto Scaling组(更改模板中EcsInstanceAsg资源的名称将导致重新创建),看看是否能解决问题。

答案 1 :(得分:0)

我得到了它的工作。解决方案是我做了以下两个更改中的一个(或两个):

  1. 我意识到我没有为ecs-cli指定VPC来在现有的VPC中启动群集。我更改了我的代码,在'ecs-cli up'调用中包含'--vpc'和'--subnets'选项。这可能是踢球者,因为as the documentation says, updating the VPCZoneIdentifier replaces the instances in the ASG, but not the ASG itself.

  2. 我删除了AutoScalingGroup的“VPCZoneIdentifier”参数周围的方括号,所以它现在看起来像这样: "VPCZoneIdentifier": { "Ref": "SubnetIds" },其中SubnetIds是两个子网ID的字符串,它们之间带有逗号。 (请注意,截至2017年2月7日,The documentation is wrong。它表示此参数采用字符串列表,但显然没有。)