我正在创建Cloudformation模板,但对某些概念感到困惑。首先,您是否需要在RouteTable中定义的每条路由中拖放一个Route对象?
或者我可以在同一条路线上添加更多DestinationCidrBlock吗?
AWS::EC2::Route
PrivateRoute:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref PrivateRouteTable
InstanceId: !Ref EC2PublicServer
DestinationCidrBlock: 0.0.0.0/0
答案 0 :(得分:1)
您不能在 DestinationCidrBlock 属性中放置多个值。它仅接受根据the documentation的字符串。
不幸的是,AWS :: EC2 :: RouteTable资源本身不能包含路由列表。因此,您需要添加与需要包含的路由一样多的AWS :: EC2 :: Route资源。
也许一种可能的解决方案是使用CloudFormation transform Macro从列表中生成多个路由资源。我不确定这是否可能。
更新:
我能够使用sample Explode macro
我编写了此模板,它运行良好,创建了指向同一Internet网关的几条路由
AWSTemplateFormatVersion: "2010-09-09"
Transform: Explode
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
Description: VPC ID of the VPC in which to create the route table
InternetGateway:
Type: String
Description: Internet gateway id
Mappings:
CidrMap:
Destination1:
Cidr: 180.1.2.0/24
Destination2:
Cidr: 200.1.1.0/24
Resources:
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VpcId
Route:
Type: AWS::EC2::Route
ExplodeMap: CidrMap
Properties:
DestinationCidrBlock: "!Explode Cidr"
GatewayId: !Ref InternetGateway
RouteTableId: !Ref RouteTable