Search

Basic

AWSTemplateFormatVersion

현재 AWS는 “2010-09-09”의 Template 버전만을 제공

Description

Template과 관련된 유용한 정보를 기록
# Example 1 Description: CloudFormation Template # Example 2 Description: > Consists of - VPC - IGW - Subnets
YAML
복사

Metadata

다음과 같이 CloudFormation에 특화된 자원들을 정의
AWS::CloudFormation::Init
AWS::CloudFormation::Interface
AWS::CloudFormation::Designer

Parameters

환경과 버전에 따라 서로 다른 값을 사용할 수 있는 Parameter 정의, Parameter “A”를 선언했을 경우, Template 내 다른 위치에서 !Ref A로 Parameter A의 값 참조 가능
속성
Type: Parameter의 종류(자료형)
AWS에 특화된 Type도 존재, 해당 Type으로 이미 존재하는 AWS 자원을 Parameter 값으로 선택
AWS::EC2::AvailabilityZone::Name
AWS::EC2::Image::Id
AWS::EC2::Instance::Id
AWS::EC2::KeyPair
AWS::EC2::VPC::Id
Default : Parameter의 기본값 정의
AllowedValues : 허용되는 Parameter 값의 목록 정의
AllowedPattern : 정규 표현식으로 허용되는 Parameter 값 제한

Mappings

Key : Value로 이루어진 Map 형태로 데이터를 저장. Map “A”를 선언했을 경우, Template 내 다른 위치에서 !FindInMap [A, “키_이름”, “키_이름”]로 Map A 내 원하는 값 참조 가능
# Example AWSTemplateFormatVersion: "2010-09-09" Mappings: RegionMap: us-east-1: HVM64: ami-0ff8a91507f77f867 HVMG2: ami-0a584ac55a7631c0c us-west-1: HVM64: ami-0bdb828fd58c52235 HVMG2: ami-066ee5fd4a9ef77f1 eu-west-1: HVM64: ami-047bb4163c506cd98 HVMG2: ami-0a7c483d527806435 ap-northeast-1: HVM64: ami-06cd52961ce9f0d85 HVMG2: ami-053cdd503598e4a9d ap-southeast-1: HVM64: ami-08569b978cc4dfa10 HVMG2: ami-0be9df32ae9f92309 Resources: myEC2Instance: Type: "AWS::EC2::Instance" Properties: ImageId: !FindInMap [RegionMap, "us-east-1", "HVM64"] InstanceType: m1.small
YAML
복사

Conditions

true 또는 false 값을 갖는 Condition을 정의, Resource에 Condition을 적용하여 Condition이 참일 경우에만 해당 Resource가 생성되도록 제한
# Example AWSTemplateFormatVersion: 2010-09-09 Parameters: EnvType: Description: Environment type. Default: test Type: String AllowedValues: - prod - test ConstraintDescription: must specify prod or test. Conditions: CreateProdResources: !Equals - !Ref EnvType - prod Resources: EC2Instance: Type: 'AWS::EC2::Instance' Properties: ImageId: ami-0ff8a91507f77f867 MountPoint: Type: 'AWS::EC2::VolumeAttachment' Condition: CreateProdResources Properties: InstanceId: !Ref EC2Instance VolumeId: !Ref NewVolume Device: /dev/sdh NewVolume: Type: 'AWS::EC2::Volume' Condition: CreateProdResources Properties: Size: 100 AvailabilityZone: !GetAtt - EC2Instance - AvailabilityZone
YAML
복사

Transform

함수를 통해 Template을 동적으로 구성하는 Macro를 정의

Resources

CloudFormation으로 모든 AWS 자원들을 생성할 수는 없습니다 AWS Organizations, Control Tower 등의 자원은 CloudFormation에서 미지원
생성/변경할 AWS 자원들을 정의
속성
Type
Properties
DependsOn
CreationPolicy
DeletionPolicy
UpdatePolicy
UpdateReplacePolicy

Outputs

Export 이름은 서로 겹치지 않도록 고유해야 함
다른 CloudFormation Stack(Template .yaml)에서 불러오기(!ImportValue) 위해 내보내기(Export)할 수 있는 Output 정의
# Example # core.yaml ... Outputs: StackVPC: Description: The ID of the VPC Value: !Ref MyVPC Export: Name: VpcId # webtier.yaml ... Resources: ... WebTierTg: Type: "AWS::ElasticLoadBalancingV2::TargetGroup" Properties: Port: 80 Protocol: HTTP VpcId: !ImportValue VpcId Tags: - Key: Env Value: !Ref Environment - Key: Name Value: !Join [ "-", [ !Ref Environment, !Ref "AWS::StackName", "lb-tg" ] ]
YAML
복사