CloudFormation中的AWS VPC默认路由表


Answers:


25

不,您不能,无论如何都没有要引用的内容(例如逻辑ID)。只需创建您自己的主表;-)。

可能是无法使用的原因之一:

保护VPC的一种方法是将主路由表保留为其原始默认状态(仅具有本地路由),并将 创建的每个新子网与已创建的自定义路由表之一明确关联。这样可确保您必须明确控制每个子网的出站流量的路由方式


3
听起来像家务。
露宿者史密斯

3
觉得不好吗?等到您分离出模板,以便每个模板只承担一个责任,而父模板将较小的模板拖入更大的堆栈中...现在,您必须将VPC RouteTable从一个模板传递给所有其他孩子模板。尽管RouteTable已经知道它属于哪个VPC,但是您无法从中提取该信息。</ rant>
DanielM 2015年

3
@DanielM听起来像一个工作github.com/SleeperSmith/Aws-Lego。看起来我们有相同的抱怨。:D哈哈哈哈。
史密斯卧铺


1

如果需要通过CloudFormation实施该设置,则可以自己定义每个组件。只需创建自己的VPC,Internet网关,子网和路由表。然后,您需要为特定子网显式声明RouteTableAssociation,并为该表创建一条公共路由。这是一个例子

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

这样,您将能够使用创建的路由表(在上面的示例中,该表用于从Internet Gateway转发流量)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.