CloudFormation으로 VPC 생성
클라우드에 대해 공부해보고자 인프런의 "AWS 클라우드 서비스 인프라 구축 이해와 해킹, 보안" 강의를 수강하면서 필기한 내용입니다.
생성 전에 vpc.yaml 파일을 다운 받는다.
vpc.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: VPC Configuration
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
Tags:
- Key: Name
Value: myVPC
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.0.0/24
AvailabilityZone: "ap-northeast-2a"
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: public subnet
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.10.0/24
AvailabilityZone: "ap-northeast-2c"
Tags:
- Key: Name
Value: private subnet
IGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: myigw
Attachigw:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref IGW
VpcId: !Ref VPC
EIP:
Type: AWS::EC2::EIP
NAT:
Type: AWS::EC2::NatGateway
DependsOn: Attachigw
Properties:
AllocationId: !GetAtt EIP.AllocationId
SubnetId: !Ref PublicSubnet
PublicRT:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: Public RT
PublicRoute:
Type: AWS::EC2::Route
DependsOn: Attachigw
Properties:
RouteTableId: !Ref PublicRT
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref IGW
PublicSubnetRTAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRT
SubnetId: !Ref PublicSubnet
PrivateRT:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: Private RT
PrivateRoute:
Type: AWS::EC2::Route
DependsOn: Attachigw
Properties:
RouteTableId: !Ref PrivateRT
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NAT
PrivateSubnetRTAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRT
SubnetId: !Ref PrivateSubnet
구성하게 된다면 아래와 같은 구조가 될 것이다.

생성을 위해 이전 실습과 같이 스택을 생성한다.


스택 생성 확인

이후 VPC를 들어가 확인해 보면 코드의 내용대로 완벽하게 생성된 것을 확인할 수 있다. (VPC, 서브넷, 탄력적 IP등등)



인스턴스 연결
인스턴스 생성


연결 성공 확인

이 역시 사용하지 않는다면 반드시 잘 삭제해야 합니다 과금이 나올 수 있으니 삭제하고 세부 내역 잘 확인하시길…
'클라우드 공부' 카테고리의 다른 글
내부 서버 프록시 옵션을 이용한 SSH 접속 (2) | 2024.10.04 |
---|---|
내부 서버 사용자 데이터를 이용하여 SSH 접속 (1) | 2024.10.04 |
CloudFormation 이해 및 기본 생성 (2) | 2024.10.04 |
AWS 클라우드 워드프레스 서비스 만들기, ALB 반영 및 웹 서비스 완성하기 (13) | 2024.08.30 |
AWS 클라우드 워드프레스 서비스 만들기, Public 대역에 워드프레스 구축하기 (0) | 2024.08.30 |