CloudFormation의 AWS VPC 기본 라우팅 테이블 있지만 CloudFormation을

누락 된 것이 있지만 CloudFormation을 통해 VPC와 함께 제공되는 기본 라우팅 테이블에 경로를 추가 할 방법이 없습니까?



답변

아니, 어쨌든 참조 할 것이 없습니다 (예 : 논리적 ID). 자신의 메인 테이블을 작성하십시오. ;-).

이것은 아마도 사용할 수없는 이유 중 하나입니다.

VPC를 보호하는 한 가지 방법은 기본 라우팅 테이블 을 원래 기본 상태 (로컬 라우팅 만 포함)로 유지하고 생성 한 각 새 서브넷 을 생성 한 사용자 지정 라우팅 테이블 중 하나 와
명시 적으로 연결하는 것입니다. 이를 통해 각 서브넷의 아웃 바운드 트래픽 라우팅 방법을 명시 적으로 제어 해야합니다 .


답변

CloudFormation을 통해 해당 설정을 구현해야하는 경우 각 구성 요소를 직접 정의 할 수 있습니다. 자신 만의 VPC, 인터넷 게이트웨이, 서브넷 및 라우팅 테이블을 생성하십시오. 그런 다음 특정 서브넷에 대한 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

이렇게하면 생성 된 라우팅 테이블을 사용할 수 있습니다 (위 예에서는 인터넷 게이트웨이에서 트래픽을 전달하는 데 사용됨)


답변