【问题标题】:CloudFormation - Template contains errors.: Invalid template parameter property 'Properties'CloudFormation - 模板包含错误。:无效的模板参数属性“属性”
【发布时间】:2018-03-29 09:46:05
【问题描述】:

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

模板代码: 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)"
}
}

}

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

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    您正在 Parameters 键下创建 VPCpublic subnet。您需要在键 resources 下定义 vpcsubnet。这应该有效:

    {
        "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)"
        }
    }
    }
    

    【讨论】:

    • 效果很好。我是云形成的新手,这就是为什么要问基本问题。非常感谢 Zohaib。
    猜你喜欢
    • 2018-12-15
    • 2016-03-19
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多