CloudFormation - 模板包含错误:无效的模板参数属性“属性”

时间:2018-03-29 09:46:05

标签: amazon-web-services amazon-cloudformation

我正在上传以下模板以在CloudFormation中创建EC2实例。当我从控制台“验证模板”获得以下错误 - 模板包含错误:无效的模板参数属性“属性”

模板代码: Template is attached. Open template with notepad or notepad++

{

"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "This is an AWS Cloud Formation template to create an EC2 instance in a Custom VPC.",

"Parameters" : {

"KeyName" : {
"Type" : "String",
"Default" : "ec2-us-east",
"Description" : "SSH Key to access the EC2 instance"
},

"MyVpc" : {
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : "10.0.0.0/16",
"EnableDnsHostnames" : "true"
}
},

"PublicSubnet" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"VpcId" : {"Ref" : "MyVpc"},
"CidrBlock" : "10.0.0.0/24",
"AvailabilityZone" : "us-east-1a"
}
},

"InstanceType" : {
"Type" : "String",
"Default" : "t2.micro",
"Description" : "Select EC2 instance type"
}

},


"Resources" : {

"SecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupName" : "My Security Group",
"GroupDescription" : "My CFSecurity Group",
"VpcId" : {"Ref" : "MyVpc"},
"SecurityGroupIngress" : [{
"CidrIp" : "0.0.0.0/0",
"FromPort" : "22",
"IpProtocol" : "tcp",
"ToPort" : "22"
}]
}
},

"Server" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-1853ac65",
"InstanceType" : {"Ref" : "InstanceType"},
"KeyName" : {"Ref" : "KeyName"},
"SecurityGroupIds" : {"Ref" : "SecurityGroup"},
"SubnetId" : {"Ref" : "PublicSubnet"}
}
}

},

"Outputs" : {
"PublicName" : {
"Value" : {"Fn::GetAtt" : ["Server", "PublicDnsName"]},
"Description" : "Public Name (connect via ssh)"
}
}

}

你能帮我找出我做错了吗?

1 个答案:

答案 0 :(得分:1)

您正在密钥VPC下创建public subnetParameters。您需要在密钥vpc下定义subnetresources。这应该有效:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "This is an AWS Cloud Formation template to create an EC2 instance in a Custom VPC.",
    "Parameters": {
        "KeyName": {
            "Type": "String",
            "Default": "ec2-us-east",
            "Description": "SSH Key to access the EC2 instance"
        },
        "InstanceType": {
            "Type": "String",
            "Default": "t2.micro",
            "Description": "Select EC2 instance type"
        }
    },

"Resources": {
    "SecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupName": "My Security Group",
            "GroupDescription": "My CFSecurity Group",
            "VpcId": {
                "Ref": "MyVpc"
            },
            "SecurityGroupIngress": [{
                "CidrIp": "0.0.0.0/0",
                "FromPort": "22",
                "IpProtocol": "tcp",
                "ToPort": "22"
            }]
        }
    },
    "Server": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "ImageId": "ami-1853ac65",
            "InstanceType": {
                "Ref": "InstanceType"
            },
            "KeyName": {
                "Ref": "KeyName"
            },
            "SecurityGroupIds": {
                "Ref": "SecurityGroup"
            },
            "SubnetId": {
                "Ref": "PublicSubnet"
            }
        }
    },
    "MyVpc": {
        "Type": "AWS::EC2::VPC",
        "Properties": {
            "CidrBlock": "10.0.0.0/16",
            "EnableDnsHostnames": "true"
        }
    },
    "PublicSubnet": {
        "Type": "AWS::EC2::Subnet",
        "Properties": {
            "VpcId": {
                "Ref": "MyVpc"
            },
            "CidrBlock": "10.0.0.0/24",
            "AvailabilityZone": "us-east-1a"
        }
    }
},
"Outputs": {
    "PublicName": {
        "Value": {
            "Fn::GetAtt": ["Server",
            "PublicDnsName"]
        },
        "Description": "Public Name (connect via ssh)"
    }
}
}