我收到“一个或多个无效模板属性”模板验证错误:一个或多个无效模板属性[IPAssoc,IPAddress]

时间:2018-09-22 16:56:08

标签: json amazon-web-services amazon-cloudformation

您好,以下是我的模板,用于在启用了弹性IP的AWS中创建实例。但是我不确定我要去哪里。我已经通过在线json验证器验证了json仍然遇到问题,请帮助

{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "My learning template",
  "Parameters" : {
    "KeyName": {
        "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server",
        "Type": "AWS::EC2::KeyPair::KeyName",
        "Default" : "Myvirginiakey",
        "ConstraintDescription" : "must be the name of an existing EC2 KeyPair."
    },
    "EC2InstanceType" : {
      "Type" : "String",
      "Default" : "t2.micro",
      "AllowedValues" : ["t2.micro", "m1.small", "m1.large"],
      "Description" : "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
    }
  },
  "IPAddress" : {
    "Type" : "AWS::EC2::EIP"
  },
  "IPAssoc" : {
    "Type" : "AWS::EC2::EIPAssociation",
    "Properties" : {
      "InstanceId" : { "Ref" : "EC2Instance" },
      "EIP" : { "Ref" : "IPAddress" }
    }
  },
  "Resources" : {
    "Ec2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Properties" : {
       "UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [ "IPAddress=", {"Ref" : "IPAddress"}]]}},
        "KeyName" : { "Ref" : "KeyName"},
        "ImageId": "ami-0912f71e06545ad88", 
        "InstanceType" : { "Ref" : "EC2InstanceType"}
      }
    }
  },
  "Outputs" : {
  }
}

错误消息是:

  

“无效的模板属性”模板验证错误:无效的模板属性[IPAssoc,IPAddress]”

1 个答案:

答案 0 :(得分:0)

您需要将IPAddressIPAssoc放在资源部分中。您在IPAddress

中也有错字

删除这两行并使用:

"Resources" : {
    "Ec2Instance" : {
        "Type" : "AWS::EC2::Instance",
        "Properties" : {
            "UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [ "IPAddress=", {"Ref" : "IPAddress"}]]}},
           "KeyName" : { "Ref" : "KeyName"},
           "ImageId": "ami-0912f71e06545ad88", 
           "InstanceType" : { "Ref" : "EC2InstanceType"}
        }
    },
    "IPAddress" : {
       "Type" : "AWS::EC2::EIP"
    },
   "IPAssoc" : {
       "Type" : "AWS::EC2::EIPAssociation",
       "Properties" : {
           "InstanceId" : { "Ref" : "Ec2Instance" },
           "EIP" : { "Ref" : "IPAddress" }
       }
   } 
},