Aws Iac - CloudFormation(2) 이란?
2023. 11. 13. 16:09ㆍDevops
반응형
Aws CloudFormation Template 구성 요소 : Aws 인프라를 생성 및 설명하는 JSON 또는 yaml 형식의 텍스트 파일.
-> Template : 포맷 버전, Description, Metadata, Parameters, Mappings, Conditions, Transform, Resource, outputs 같은 섹션 으로 구별 (제일 중요한 섹션은 Resource이다.)
Parameters 섹션 : Stack 생성 시 리소스와 outputs 세션에서 참조 할 수 있는 값들을 지정하는 섹션으로 parameter를 전달 하기 위해 사용자가 직접 타이핑 하거나, 선택 옵션을 통하여 선택 할 수 있도록 설정 필요하다.(Resource수량, 크기 설정)
Resource 섹션 : ec2 or s3 등 스택에 포함한 Aws 리소스 선언을 할 때 사용 한다. Resoucre 섹션은 ec2, s3생성을 위해 필요한 속성값 및 keypair 파라미터 값에 대한 참조를 포함한다.
Outputs : Stack 생성을 위해 템플릿의 모든 수행을 완료 한 후 작업의 결과물로 전달 받을 수 있는 인스턴스ID, EIP 템플릿 수행 후 결과값에 대한 정보를 리턴 받을 수 있는 섹션
Cloud Formation 예시 파일
AWSTemplateFormatVersion: 2010-09-09
Description: Make a VPC 2
Resources:
TestVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 172.0.0.0/16
EnableDnsHostnames: true
InternetGateway:
Type: AWS::EC2::InternetGateway
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref TestVPC
InternetGatewayId: !Ref InternetGateway
PublicSubnet01:
Type: Aws::EC2::Subnet
properties:
VpcID: !Ref TotourialVPC
CidrBlock: 172.0.2.0/24
AvailabilityZone: !Select
- '1'
- !GetAZs ''
PrivateSubnet01:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref TestVPC
CidrBlock: 172.0.3.0/24
AvailabilityZone: !Select
- '0'
- !GetAZs ''
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref TestVPC
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 PublicSubnet01
RouteTableId: !Ref PublicRouteTable
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref TestVPC
PrivateSubnetRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet01
RouteTableId: !Ref PrivateRouteTable
Outputs:
VPC:
Description: Test VPC ID
Value: !Ref TestVPC
AZ1:
Description: Availability Zone 1
Value: !GetAtt
- PublicSubnet01
- AvailabilityZone
반응형
'Devops' 카테고리의 다른 글
Aws SES에서 발송 실패 내역 Slack으로 알람 수신. (0) | 2025.04.05 |
---|---|
Aws Iac - CloudFormation(1) 이란? (0) | 2023.11.13 |
Docker 사항 4 : Docker vs Docker Compose (0) | 2023.09.26 |
Docker 시작하기 -3장 커맨드 치트 시트 (0) | 2023.09.11 |
Docker 시작 사항 -2 Docker 아키텍쳐 (0) | 2023.09.06 |