[AWS] Multi-AZ 구성 시 VPC CloudFormation Template

11081 단어 CloudFormationvpcAWS
Multi-AZ VPC 환경을 구성하는 CloudFormation Template를 만들었습니다.
다음 순서로 Multi-AZ 구성에 필요한 일반적인 NW 환경이 구축됩니다.

· VPC 작성
· IGW 작성 · 부착
· Subnets 작성
· NAT 게이트웨이 만들기
· RouteTable 작성

구성





VPC의 CIDR, AZ는 구축시의 Parameter에서 임의로 설정할 수 있습니다.
또한 모든 지역에서 사용할 수 있습니다.

사용법



· 아래에있는 Template를 저장하고 CloudFormation의 "CreateStack"에서 스택 만들기 시작
· Parameters로 다음을 입력
- Multi-AZ에서 사용할 AZ를 2개 선택 (AZ1/AZ2)
- VPCCIDR에 만들려는 네트워크 주소 입력(10.* 또는 172.16 ~ 172.31 또는 192.168)
・작성 완료까지 기다린다(NatGateway에서 조금 시간이 걸립니다)



Template


{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "VPC Template For Multi-AZ",
  "Parameters": {
    "AZ1" : {
        "Description" : "input Availability Zone 1",
        "Type"        : "AWS::EC2::AvailabilityZone::Name"
    },
    "AZ2" : {
        "Description" : "input Availability Zone 2",
        "Type"        : "AWS::EC2::AvailabilityZone::Name"
    },
    "VPCCIDR": {
      "AllowedPattern" : "^(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])",
      "Default"        : "10.0",
      "Description"    : "VPC CIDR (*.*.0.0/16)",
      "Type"           : "String"
    }
  },
  "Resources": {
    "vpc00": {
      "Type"       : "AWS::EC2::VPC",
      "Properties" : {
        "CidrBlock"          : { "Fn::Join": [ "", [ { "Ref": "VPCCIDR" }, ".0.0/16" ] ] },
        "InstanceTenancy"    : "default",
        "EnableDnsSupport"   : "true",
        "EnableDnsHostnames" : "false",
        "Tags"               : [ { "Key": "Name", "Value": "TestVPC" } ]
      }
    },
    "eip0001": {
      "Type"       : "AWS::EC2::EIP",
      "Properties" : { "Domain" : "vpc" }
    },
    "eip0002": {
      "Type"       : "AWS::EC2::EIP",
      "Properties" : { "Domain" : "vpc" }
    },
    "subnetPub1": {
      "Type"       : "AWS::EC2::Subnet",
      "Properties" : {
        "CidrBlock"        : { "Fn::Join": [ "", [ { "Ref": "VPCCIDR" }, ".0.0/24" ] ] },
        "AvailabilityZone" : { "Ref" : "AZ1" },
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Public-Subnet-1" } ]
      }
    },
    "subnetPub2": {
      "Type"       : "AWS::EC2::Subnet",
      "Properties" : {
        "CidrBlock"        : { "Fn::Join": [ "", [ { "Ref": "VPCCIDR" }, ".1.0/24" ] ] },
        "AvailabilityZone" : { "Ref" : "AZ2" },
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Public-Subnet-2" } ]
      }
    },
    "subnetPrv1": {
      "Type"       : "AWS::EC2::Subnet",
      "Properties" : {
        "CidrBlock"        : { "Fn::Join": [ "", [ { "Ref": "VPCCIDR" }, ".2.0/24" ] ] },
        "AvailabilityZone" : { "Ref" : "AZ1" },
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Private-Subnet-1" } ]
      }
    },
    "subnetPrv2": {
      "Type"       : "AWS::EC2::Subnet",
      "Properties" : {
        "CidrBlock"        : { "Fn::Join": [ "", [ { "Ref": "VPCCIDR" }, ".3.0/24" ] ] },
        "AvailabilityZone" : { "Ref" : "AZ2" },
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Private-Subnet-2" } ]
      }
    },
    "Nat1": {
      "Type"       : "AWS::EC2::NatGateway",
      "Properties" : {
        "AllocationId"     : { "Fn::GetAtt" : ["eip0001", "AllocationId"] },
        "SubnetId"         : { "Ref" : "subnetPub1" }
      },
      "DependsOn"  : "eip0001"
    },
    "Nat2": {
      "Type"       : "AWS::EC2::NatGateway",
      "Properties" : {
        "AllocationId"     : { "Fn::GetAtt" : ["eip0002", "AllocationId"] },
        "SubnetId"         : { "Ref" : "subnetPub2" }
      },
      "DependsOn"  : "eip0002"
    },
    "IGW": {
      "Type"       : "AWS::EC2::InternetGateway",
      "Properties" : {
        "Tags"             : [ { "Key": "Name", "Value": "Test-IG" } ]
      }
    },
    "RouteTablePub1": {
      "Type"           : "AWS::EC2::RouteTable",
      "Properties"     : {
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Public-RT-A" } ]
      }
    },
    "RouteTablePub2": {
      "Type"           : "AWS::EC2::RouteTable",
      "Properties"     : {
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Public-RT-C" } ]
      }
    },
    "RouteTablePrv1": {
      "Type"           : "AWS::EC2::RouteTable",
      "Properties"     : {
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Private-RT-A" } ]
      }
    },
    "RouteTablePrv2": {
      "Type"           : "AWS::EC2::RouteTable",
      "Properties"     : {
        "VpcId"            : { "Ref": "vpc00" },
        "Tags"             : [ { "Key": "Name", "Value": "Private-RT-C" } ]
      }
    },
    "gw1": {
      "Type"           : "AWS::EC2::VPCGatewayAttachment",
      "Properties"     : {
        "VpcId"             : { "Ref": "vpc00" },
        "InternetGatewayId" : { "Ref": "IGW" }
      }
    },
    "subnetRoutePub1": {
      "Type"           : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties"     : {
        "RouteTableId"     : { "Ref": "RouteTablePub1" },
        "SubnetId"         : { "Ref": "subnetPub1" }
      }
    },
    "subnetRoutePub2": {
      "Type"           : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties"     : {
        "RouteTableId"     : { "Ref": "RouteTablePub2" },
        "SubnetId"         : { "Ref": "subnetPub2" }
      }
    },
    "subnetRoutePrv1": {
      "Type"           : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties"     : {
        "RouteTableId"     : { "Ref": "RouteTablePrv1" },
        "SubnetId"         : { "Ref": "subnetPrv1" }
      }
    },
    "subnetRoutePrv2": {
      "Type"           : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties"     : {
        "RouteTableId"     : { "Ref": "RouteTablePrv2" },
        "SubnetId"         : { "Ref": "subnetPrv2" }
      }
    },
    "routePub101": {
      "Type"           : "AWS::EC2::Route",
      "Properties"     : {
        "DestinationCidrBlock"  : "0.0.0.0/0",
        "RouteTableId"          : { "Ref": "RouteTablePub1" },
        "GatewayId"             : { "Ref": "IGW" }
      },
      "DependsOn"      : "gw1"
    },
    "routePub201": {
      "Type"           : "AWS::EC2::Route",
      "Properties"     : {
        "DestinationCidrBlock"  : "0.0.0.0/0",
        "RouteTableId"          : { "Ref": "RouteTablePub2" },
        "GatewayId"             : { "Ref": "IGW" }
      },
      "DependsOn"      : "gw1"
    },
    "routePrv101": {
      "Type"           : "AWS::EC2::Route",
      "Properties"     : {
        "DestinationCidrBlock"  : "0.0.0.0/0",
        "RouteTableId"          : { "Ref": "RouteTablePrv1" },
        "NatGatewayId"          : { "Ref" : "Nat1" }
      },
      "DependsOn"      : [ "Nat1" , "subnetRoutePrv1" ]
    },
    "routePrv201": {
      "Type"           : "AWS::EC2::Route",
      "Properties"     : {
        "DestinationCidrBlock"  : "0.0.0.0/0",
        "RouteTableId"          : { "Ref": "RouteTablePrv2" },
        "NatGatewayId"          : { "Ref" : "Nat2" }
      },
      "DependsOn"      : [ "Nat2" , "subnetRoutePrv2" ]
    },
    "dchpOpt": {
      "Type"           : "AWS::EC2::DHCPOptions",
      "Properties"     : {
        "DomainName"           : "ec2.internal.com",
        "DomainNameServers"    : [ "AmazonProvidedDNS"]
      }
    },
    "dchpAssoc": {
      "Type"           : "AWS::EC2::VPCDHCPOptionsAssociation",
      "Properties"     : {
        "VpcId"            : { "Ref": "vpc00" },
        "DhcpOptionsId"    : {"Ref" : "dchpOpt" }
      },
      "DependsOn"      : "dchpOpt"
    }
  }
}

좋은 웹페이지 즐겨찾기