![](/img/trans.png)
[英]AWS CloudFormation: how do I refer to the default/main route table (that is created when a VPC is created) in a cloudformation template?
[英]AWS Cloudformation Stack - Route Table Main
是否可以在 cloudformation 堆棧模板中指定添加路由表並將其設置為 main:yes 時?
在我當前的堆棧模板上,始終有一個與我的 VPC(也由堆棧創建)關聯的路由表設置為 main:yes 但它沒有在我的堆棧模板上指定路由表。
不,這是不可能的。
創建 VPC 時,會自動創建“主”路由表,這將是所有未指定子網關聯的子網的默認路由表。
無法通過具有此屬性的 CloudFormation 創建子網。
為了創建類似的設置,您需要自己為基礎設施編寫整個堆棧:VPC、Internet 網關、子網和路由表。 然后您需要為特定子網顯式定義 RouteTableAssociation 並為表創建公共路由。 這種設置的 YAML 示例
AWSTemplateFormatVersion: '2010-09-09'
Description: Example
Resources:
myInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: "Name"
Value: "a_gateway"
myVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/24
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
# Attach Internet gateway to created VPC
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: myVPC
InternetGatewayId:
Ref: myInternetGateway
# Create public routes table for VPC
myPublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref myVPC
Tags:
- Key: "Name"
Value: "public_routes"
# Create a route for the table which will forward the traffic
# from the gateway
myDefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref myPublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref myInternetGateway
# Subnet within VPC which will use route table (with default route)
# from Internet gateway
mySubnet:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ""
CidrBlock: 10.0.0.0/25
MapPublicIpOnLaunch: true
VpcId:
Ref: myVPC
# Associate route table (which contains default route) to newly created subnet
myPublicRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref myPublicRouteTable
SubnetId: !Ref mySubnet
模板並不是很短,但要完成這個簡單的要求,您必須明確定義所有內容。
保護您的 VPC 的一種方法是將主路由表保留在其原始默認狀態(只有本地路由),並將您創建的每個新子網與您創建的自定義路由表之一明確關聯。 這確保您必須明確控制如何路由每個子網的出站流量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.