brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jan 02. 2022

 20탄-클라우드 포메이션,Pub2,Pri2,NAT

CloudFormation

테스트하거나 서비스할 때  CloudFormation 파일로 네트워크를 바로 만들어 사용하자.

AWS 구축 자동화 툴인 CloudFormation을 Excel로 알아보자.

리소스 생성시 기본 설정할 타입과 추가 구성시 필요한 타입수를 알아보자.



<1> Excel로 정리해보는 CloudFormation 설정

<2>  Public Subnet 2개, Private Subnet 2개,  NAT 생성을 CloudFormation 으로 해보자

<3> (몰아보기) CloudFormation 



<1> Excel로 정리해보는 CloudFormation 설정


 Public Subnet 1개, Private Subnet 1개,  NAT 와

 Public Subnet 2개, Private Subnet 2개,  NAT  비교




<2>  Public Subnet 2개, Private Subnet 2개,  NAT 생성을 CloudFormation 으로 해보자


1

 Public Subnet 1개, Private Subnet 1개,  NAT 


참고

 Public Subnet 1개, Private Subnet 1개,  NAT  1개 생성

https://brunch.co.kr/@topasvga/1915



2

 Public Subnet 2개, Private Subnet 2개,  NAT 



3

Public Subnet 2개, Private Subnet 2개,  NAT 


NAT가 생성 되므로 비용이 발생된다.

테스트의 경우 빠르게 테스트하고 삭제해야 비용이 적게 나온다.




AWSTemplateFormatVersion: 2010-09-09

Description: Deploy a VPC


Resources:

  VPC:

    Type: AWS::EC2::VPC

    Properties:

      CidrBlock: 10.0.0.0/16

      EnableDnsHostnames: true

      Tags:

      - Key: Name

        Value: Lab VPC


  InternetGateway:

    Type: AWS::EC2::InternetGateway

    Properties:

      Tags:

      - Key: Name

        Value: Lab Internet Gateway


  AttachGateway:

    Type: AWS::EC2::VPCGatewayAttachment

    Properties:

      VpcId: !Ref VPC

      InternetGatewayId: !Ref InternetGateway



  PublicSubnet1:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.0.0/24

      AvailabilityZone: !Select 

        - '0'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Public Subnet 1  


  PublicSubnet2:

    Type: AWS::EC2::Subnet

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.2.0/24

      AvailabilityZone: !Select 

        - '1'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Public Subnet 2



# 1

  PrivateSubnet1:

    Type: AWS::EC2::Subnet    

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.1.0/24

      AvailabilityZone: !Select 

        - '0'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Private Subnet 1


  PrivateSubnet2:

    Type: AWS::EC2::Subnet    

    Properties:

      VpcId: !Ref VPC

      CidrBlock: 10.0.3.0/24

      AvailabilityZone: !Select 

        - '1'

        - !GetAZs ''

      Tags:

        - Key: Name

          Value: Private Subnet 2          


  PublicRouteTable:

    Type: AWS::EC2::RouteTable

    Properties:

      VpcId: !Ref VPC

      Tags:

        - Key: Name

          Value: Public Route Table


  PublicRoute:

    Type: AWS::EC2::Route

    Properties:

      RouteTableId: !Ref PublicRouteTable

      DestinationCidrBlock: 0.0.0.0/0

      GatewayId: !Ref InternetGateway


  PublicSubnetRouteTableAssociation1:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PublicSubnet1

      RouteTableId: !Ref PublicRouteTable


  PublicSubnetRouteTableAssociation2:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PublicSubnet2

      RouteTableId: !Ref PublicRouteTable      



# nat1

  NATGW01:

    Type: AWS::EC2::NatGateway    

    Properties:

      AllocationId: !GetAtt EIP.AllocationId

      SubnetId: !Ref PrivateSubnet1


# nat2

  EIP:

    DependsOn: AttachGateway

    Type: AWS::EC2::EIP    

    Properties:

      Domain: vpc


# 2

  PrivateRouteTable:

    Type: AWS::EC2::RouteTable

    Properties:

      VpcId: !Ref VPC

      Tags:

      - Key: Name

        Value: Private Route Table  



# nat 3

  PrivateRoute:

    Type: AWS::EC2::Route    

    Properties:

      RouteTableId: !Ref PrivateRouteTable

      DestinationCidrBlock: 0.0.0.0/0

      NatGatewayId: !Ref NATGW01


# 3

  PrivateSubnetRouteTableAssociation1:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PrivateSubnet1

      RouteTableId: !Ref PrivateRouteTable      

  PrivateSubnetRouteTableAssociation2:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref PrivateSubnet2

      RouteTableId: !Ref PrivateRouteTable      



Outputs:

  VPC:

    Description: VPC

    Value: !Ref VPC

  AZ1:

    Description: Availability Zone 1

    Value: !GetAtt 

      - PublicSubnet1

      - AvailabilityZone




<3> (몰아보기) CloudFormation 


https://brunch.co.kr/@topasvga/1781


감사합니다.

매거진의 이전글 20탄-9. CF -Pub1,Pri1,EC2 1개,EC
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari