AWS CloudFormation堆栈 - 路由表主要。

6
能否在云形成堆栈模板中指定添加路由表并将其设置为主要路由表?
在我的当前堆栈模板中,始终有一个与我的VPC关联的路由表(也是由堆栈创建的),该路由表设置为主要路由表,但是在我的堆栈模板中没有指定路由表。
2个回答

4

不,这是不可能的。

当创建VPC时,会自动创建一个名为“Main”的路由表,它将成为所有未指定子网关联的子网的默认路由表。

无法通过CloudFormation创建具有此属性的子网。


1
为了创建类似的设置,您需要自己编写基础架构的整个堆栈:VPC、Internet Gateway、子网和路由表。然后,您需要明确定义特定子网的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的一种方法是保留主路由表处于其原始默认状态(仅具有本地路由),并显式地将您创建的每个新子网与您创建的自定义路由表之一关联起来。这确保您必须明确控制每个子网的出站流量如何路由。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接