Getting "Template validation error: Invalid template resource property 'VPCID' "

Getting "Template validation error: Invalid template resource property 'VPCID' "

我正在尝试使用 AWS CloudFormation 创建 VPC。

我自己构建了一个 VPC,然后通过向 JSON 模板添加更多组件(子网、互联网网关、NAT、路由表等组件)更新了现有堆栈 - 一个组件一次。

我的 VPC 创建成功,但是当我尝试使用互联网网关更新堆栈并连接到 VPC 时,我开始收到错误 Template validation error: Invalid template resource property 'VPCID'

我的JSON模板如下:

{
"Parameters": {  
   "CIDRRange": { 
     "Description": "VPCCIDR Range (will be a /16 block)",
     "Type": "String",
     "Default": "10.251.0.0",
     "AllowedValues": ["10.250.0.0","10.251.0.0"]
                } 
              }, 

"Resources": { 
   "VPCBase": { 
     "Type": "AWS::EC2::VPC",
     "Properties": { 
     "CidrBlock": { "Fn::Join" : ["", [{ "Ref" : "CIDRRange" }, "/16"]] },
     "EnableDnsSupport": "True",
     "EnableDnsHostnames": "True",
     "Tags": [{ "Key": "Name", "Value":    { "Fn::Join" : ["", [{ "Ref" : "AWS::StackName" }, "-VPC"]] } }]
                   }
               },
             
   "IGWBase" : {
     "Type" : "AWS::EC2::InternetGateway",
     "Properties" : {
     "Tags" : [{ "Key": "Name", "Value": { "Fn::Join" : ["", [{ "Ref" : "AWS::StackName" }, "-IGW"]] } }]
                    }
               },

   "VGAIGWBase" : {
     "Type" : "AWS::EC2::VPCGatewayAttachment",
     "Properties" : {
     "InternetGatewayId" : { "Ref" : "IGWBase" },
     "VpcId" : { "Ref" : "VPCBase" }}
                  },

   "Outputs": {
     "VPCID" : { "Value" : { "Ref" : "VPCBase" } },
     "DefaultSG" : { "Value" : { "Fn::GetAtt" : ["VPCBase", "DefaultSecurityGroup"] }}
              }
}
}

您的格式有点乱 - 我建议使用 yaml 而不是 json - 但问题是您没有关闭资源:部分。

您可以使用

的 cli 验证模板
aws cloudformation validate-template --template-body file://path.json



  "VGAIGWBase" : {
    "Type" : "AWS::EC2::VPCGatewayAttachment",
    "Properties" : {
      "InternetGatewayId" : { "Ref" : "IGWBase" },
      "VpcId" : { "Ref" : "VPCBase" }
    }
  }
},   << ADD THIS

"Outputs": {
  "VPCID" : { "Value" : { "Ref" : "VPCBase" } },
  "DefaultSG" : { "Value" : { "Fn::GetAtt" : ["VPCBase", "DefaultSecurityGroup"] }}
  }
}