【问题标题】:CloudFormation AWS::EC2::RouteCloudFormation AWS::EC2::Route
【发布时间】:2019-10-23 17:46:00
【问题描述】:

我正在创建一个 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

【问题讨论】:

  • 不要在你的问题中表达感谢,看看它的外观并确保你的代码/数据是可读的(通过选择块并单击{},使用 4 个空格缩进数据)
  • 我粘贴了由 CloudFormation 生成的代码,它看起来很好,我不知道发生了什么。为什么不在帖子里感谢?这不是问题,我在段落底部表示感谢。
  • 仅粘贴代码还不够好,您必须对其进行格式化(您可以通过单击“X 小时前编辑”链接查看它的外观。游览清楚地说明“不要分心”,因此,您应该从问题中省略任何不能使其更清楚的内容,即任何不必要的干扰(问候、感谢、提前感谢、乞求等)。通过点赞有用的答案来表示感谢。

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


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-01
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 2014-09-22
    • 2014-01-01
    • 1970-01-01
    相关资源
    最近更新 更多