【问题标题】:Cloudformation : VPC security groups may not be used for a non-VPC launchCloudformation:VPC 安全组不能用于非 VPC 启动
【发布时间】:2016-11-23 06:37:48
【问题描述】:

以下是我的带有 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 启动多个实例。

我在这里做错了什么。

谢谢。

【问题讨论】:

    标签: amazon-cloudformation


    【解决方案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

    【讨论】:

    • 我已经添加了代码,但我仍然面临同样的错误。
    猜你喜欢
    • 2014-04-17
    • 2015-10-12
    • 2020-10-28
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 2021-06-28
    • 2017-08-08
    • 2016-05-12
    相关资源
    最近更新 更多