【问题标题】:AWS Cloudformation Stack - Route Table MainAWS Cloudformation 堆栈 - 主路由表
【发布时间】:2019-04-06 10:06:46
【问题描述】:

是否可以在 cloudformation 堆栈模板中指定添加路由表并将其设置为 main:yes?

在我当前的堆栈模板上,始终有一个与我的 VPC 关联的路由表(也由堆栈创建)设置为 main:yes,但它没有在我的堆栈模板上指定路由表。

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    不,这是不可能的。

    创建 VPC 时,会自动创建一个“主”路由表,这将是所有未指定子网关联的子网的默认路由表。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2018-08-06
        • 2021-03-31
        • 2017-10-18
        • 1970-01-01
        • 2023-03-07
        • 2021-06-04
        • 1970-01-01
        • 2015-10-23
        • 2020-05-07
        相关资源
        最近更新 更多