YAML
, JSON
Teplmate 기반으로 AWS 자원 생성=> AWS 자원(람다, DB 등)을 생성하기 위해 일일이 스펙을 설정하고 선택(Click)할 필요 없이 Template만 명시하면 자동으로 생성
=> 팀 단위로 AWS 자원을 관리할 때 용이
AWSTemplateFormatVersion: 2010-09-09
Description: Template to create an EC2 instance and enable SSH
# Resouces 생성에 필요한 Prameter 명시(CloudFormation 생성 시 설정해줌)
Parameters:
KeyName:
Description: Name of SSH KeyPair
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: Provide the name of an existing SSH key pair
# 만들어줄 AWS Resources
Resources:
MyEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: t2.micro
ImageId: ami-0a0064415cdedc552 # Resource ID
KeyName: !Ref KeyName # 참조할 때, !Ref 이름
SecurityGroups:
- Ref: InstanceSecurityGroup
Tags:
- Key: Name
Value: My CF Instance
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
# 결과물
Outputs:
InstanceID:
Description: The Instance ID
Value: !Ref MyEC2Instance
ResourceId
템플릿 지정
스택 이름 지정 및 파라미터로 설정했던 키페어 설정
생성 결과