能否在云形成堆栈模板中指定添加路由表并将其设置为主要路由表?
在我的当前堆栈模板中,始终有一个与我的VPC关联的路由表(也是由堆栈创建的),该路由表设置为主要路由表,但是在我的堆栈模板中没有指定路由表。
在我的当前堆栈模板中,始终有一个与我的VPC关联的路由表(也是由堆栈创建的),该路由表设置为主要路由表,但是在我的堆栈模板中没有指定路由表。
不,这是不可能的。
当创建VPC时,会自动创建一个名为“Main”的路由表,它将成为所有未指定子网关联的子网的默认路由表。
无法通过CloudFormation创建具有此属性的子网。
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