AWS 인프라에 대해 코드로 선언하는 방법이다. 미리 코드로 적어둔 AWS 인프라 자원을 생성하거나 삭제할 수 있다. 비슷한 서비스로는 Terraform이 존재하고 이를 통틀어 IaC (Infrastructure as Code) 라고 부른다.
템플릿
생성할 인프라 자원을 코드로 정의한 파일 JSON, YAML 형식을 사용할 수 있다.
생성 순서
템플릿을 CloudFormation에 업로드
CloudFormation에서 스택 생성 명령
AWS가 자동으로 템플릿에 작성된 순서대로 자동으로 생성
삭제 순서
CloudFormation에서 스택 삭제 명령
AWS가 자동으로 인프라 자원을 삭제
실습
스택 생성
Parameters: KeyName: Description: Name of an existing EC2 KeyPair to enable SSH access to the instances. Linked to AWS Parameter Type: AWS::EC2::KeyPair::KeyName ConstraintDescription: must be the name of an existing EC2 KeyPair. LatestAmiId: Description: (DO NOT CHANGE) Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>' Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' AllowedValues: - /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2