Cloudformation:VPC安全组不能用于非VPC启动

时间:2016-07-20 06:53:00

标签: amazon-cloudformation

以下是我的模板,包括vpc,子网,安全组,启动配置和自动扩展。 我能够创建lauch配置和自动缩放组,但我的自动缩放组不会启动实例。 我面临VPC security groups may not be used for a non-VPC launch错误。

   {
    "myvpc": {
        "Type": "AWS: : EC2: : VPC",
        "Properties": {
            "CidrBlock": "10.0.0.0/16",
            "EnableDnsSupport": "true",
            "EnableDnsHostnames": "true",
            "InstanceTenancy": "default"
        }
    },
    "mySubnet": {
        "Type": "AWS::EC2::Subnet",
        "Properties": {
            "VpcId": {
                "Ref": "myvpc"
            },
            "CidrBlock": "10.0.1.0/24",
            "AvailabilityZone": "us-east-1a",
            "Tags": [
                {
                    "Key": "mysubnet",
                    "Value": "mysubnet"
                }
            ]
        }
    },
    "ec2Security": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription": "my CloudFormation security group",
            "VpcId": {
                "Ref": "myvpc"
            },
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "-1",
                    "FromPort": "-1",
                    "ToPort": "-1",
                    "CidrIp": "0.0.0.0/0"
                }
            ],
            "SecurityGroupEgress": [
                {
                    "IpProtocol": "-1",
                    "FromPort": "-1",
                    "ToPort": "-1",
                    "CidrIp": "0.0.0.0/0"
                }
            ]
        }
    },
    "WebServerGroup": {
        "Type": "AWS::AutoScaling::AutoScalingGroup",
        "Properties": {
            "AvailabilityZones": [
                {
                    "Fn::GetAtt": [
                        "mySubnet",
                        "AvailabilityZone"
                    ]
                }
            ],
            "LaunchConfigurationName": {
                "Ref": "WebServerLaunchConfig"
            },
            "MinSize": "1",
            "MaxSize": "10",
            "DesiredCapacity": {
                "Ref": "DesiredInstances"
            }
        }
    },
    "WebServerLaunchConfig": {
        "Type": "AWS::AutoScaling::LaunchConfiguration",
        "Properties": {
            "ImageId": "ami-xxxxx",
            "InstanceType": {
                "Ref": "InstanceType"
            },
            "KeyName": "xxxxxxxx",
            "SecurityGroups": [
                {
                    "Ref": "ec2Security"
                }
            ]
        }
    }
}

我想使用Cloudformation在VPC中的不同az中启动多个实例。

我在这里做错了什么。

谢谢。

1 个答案:

答案 0 :(得分:1)

此模板中缺少VPC:

"VpcId" : {"Ref" : "myvpc"},

此代码表示您应该在此模板中创建名为“myvpc”的vpc。就像“ec2Security”或“mySubnet”一样。 如果您不想创建新的VPC,请指定实际的VpcId而不是引用。

例如:

"VpcId" : "vpc-a6a673c1"

有关如何正确指定VpcId的更多详细信息,请访问: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html#cfn-ec2-securitygroup-vpcid