获取"模板验证错误:模板资源属性无效' VPCID' "

时间:2017-10-14 22:22:21

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

问题描述

Stack:AWS

服务:云形成

我想要实现的目标:尝试使用云形成来形成VPC

更多详情:

1.用云形成双手。

2.使用云形成[JSON]逐步构建VPC。

  1. 单独建立一个vpc
  2. 通过向JSON模板添加更多组件来更新现有堆栈
  3. 子网,Internet网关,NAT,路由表等组件
  4. 我想一次追加一个组件。所以每当我进行更新时,我只添加一个组件,我也在注意这个序列。
  5. 面临的问题:      使用第一个模板,单独创建了VPC。当我尝试使用Internet网关更新堆栈并附加到VPC时,开始收到错误"模板验证错误:模板资源属性无效' 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"] }}
                  }
    }
    }
    

1 个答案:

答案 0 :(得分:3)

你的格式有点混乱 - 我建议你使用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"] }}
  }
}
相关问题