2017-02-24 74 views
4

我正在使用CloudFormation創建整個堆棧。我已經注意到,即使我的0.0.0.0/0路由規則在我的雲形成模板中訪問互聯網網關,它也沒有被創建。Cloudformation:VPC路由表,無Internet路由的路由

VPC:

"vpc": { 
    "Type": "AWS::EC2::VPC", 
    "Properties": { 
    "CidrBlock": "172.31.0.0/16", 
    "InstanceTenancy": "default", 
    "EnableDnsSupport": "true", 
    "EnableDnsHostnames": "true", 
    "Tags": [ 
     { 
     "Key": "Environment", 
     "Value": { 
      "Ref": "Env" 
     } 
     } 
    ] 
    } 

路由表:

"rtb": { 
    "Type": "AWS::EC2::RouteTable", 
    "Properties": { 
    "VpcId": { 
     "Ref": "vpc" 
    } 
    }, 
    "Metadata": { 
    "AWS::CloudFormation::Designer": { 
     "id": "65297cdc-8bcd-482d-af40-b0fef849b8c2" 
    } 
    } 
} 

VPCGatewayAttachment:

"gw1": { 
    "Type": "AWS::EC2::VPCGatewayAttachment", 
    "Properties": { 
    "VpcId": { 
     "Ref": "vpc" 
    }, 
    "InternetGatewayId": { 
     "Ref": "ig" 
    } 
    }, 
    "Metadata": { 
    "AWS::CloudFormation::Designer": { 
     "id": "aa69d6c0-3b11-43be-a8c1-7e79176f8c89" 
    } 
    } 
} 

路線:

"route1": { 
    "Type": "AWS::EC2::Route", 
    "Properties": { 
    "DestinationCidrBlock": "0.0.0.0/0", 
    "RouteTableId": { 
     "Ref": "rtb" 
    }, 
    "GatewayId": { 
     "Ref": "ig" 
    } 
    }, 
    "DependsOn": "gw1", 
    "Metadata": { 
    "AWS::CloudFormation::Designer": { 
     "id": "a68dd12e-3c14-4fa9-ba36-e0046374a0e9" 
    } 
    } 
} 

互聯網網關:

"ig": { 
    "Type": "AWS::EC2::InternetGateway", 
    "Properties": {}, 
    "Metadata": { 
    "AWS::CloudFormation::Designer": { 
     "id": "9f9b4ce3-b994-43ff-9155-04aeb7ab2edf" 
    } 
    } 
} 

所有的項目都被創建,除了VPC的IG路由規則。在創建cloudformation堆棧時沒有錯誤。

路由表:

Destination: 172.31.0.0/16 
Target: local 

預計路由表:

Destination: 172.31.0.0/16 
Target: local 
Destination: 0.0.0.0/0 
Target: igw-******** 

注意,我可以cloudformation堆棧創建後直接通過自己添加規則。

有什麼我失蹤?

+0

資源看起來是正確的,以我 - 請添加您的堆棧事件歷史的全部輸出(['Events'](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-控制檯中的console-view-stack-data-resources.html)選項卡),以防出現異常情況。 – wjordan

+0

我認爲分享我的堆棧的整個輸出有點不安全。我剛剛檢查了兩次,沒有錯誤或警告,都具有CREATE_COMPLETE的狀態。先創建'ig',然後'vpc',然後'rtb'和'gw1',最後'route1'。我認爲這是一個錯誤。 – zed

回答

3

聯繫AWS支持後發現,每個VPC都會自動創建一個路由表,並且默認情況下會爲其所有子網設置路由表。解決方案是使用SubnetRouteTableAssociation將我的新路由表與每個子網相關聯。

"subnet0RTA": { 
     "Type" : "AWS::EC2::SubnetRouteTableAssociation", 
     "Properties" : { 
     "RouteTableId" : {"Ref" : "rtb"}, 
     "SubnetId" : {"Ref" : "subnet0"} 
     } 
    }, 
    "subnet1RTA": { 
     "Type" : "AWS::EC2::SubnetRouteTableAssociation", 
     "Properties" : { 
     "RouteTableId" : {"Ref" : "rtb"}, 
     "SubnetId" : {"Ref" : "subnet1"} 
     } 
    }, 
+0

非常感謝,謝謝你,這真的很有幫助。 – Jeet