CloudFormation

 


CloudFormation

AWS 리소스를 모델링하고 프로비저닝할 수 있도록 제공된 IAC ( Infrastructure as code ) 서비스 입니다.

주요 기능은 아래와 같습니다.

  1. 자동화 및 배포
  2. 거의 모든 AWS 리소스를 모델링
  3. JSON/YAML 로 인프라 작성
  4. 시각적 설계 가능
  5. 안전제어 ( 경보 알림 및 자동 롤백 )
  6. 종속성 관리

관련 사이트들은 아래와 같습니다.

  1. CloudFormation site : https://aws.amazon.com/ko/cloudformation/
  2. CloudFormation Guide : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide
  3. Resource Reference : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html

개념

stack

단일 단위로 관리 할 수 있는 AWS 리소스 모음입니다. stack 의 모든 리소스는 CloudFormation의 Template 에 의해 정의됩니다.

AWS에 필요한 모든 리소스를 포함될 수 있으며, 더 이상 필요하지 않은 경우 stack을 삭제하면 관련 리소스가 모두 삭제됩니다.

infrastructure as code 이미지 검색결과

설치

AWS CLI 로 동작 확인을 원할 경우 아래 링크에서 aws-cli를 설치합니다.

link: https://docs.aws.amazon.com/cli/latest/userguide/install-windows.html

워크 플로우

  1. 인프라 코드 작성
  2. 스택 생성 및 배포
  3. 스택 삭제

인프라 코드 작성

여기서 간단한 Lambda 함수를 생성하는 샘플코드를 실행해 봅니다.

template.yaml 파일 생성후 편집하세요.

template.yaml
AWSTemplateFormatVersion: 2010-09-09
Resources:
  lambdaFunction:
    Type: "AWS::Lambda::Function"
    Properties:
      FunctionName: "test_lambda"
      Handler: "index.handler"
      Code:
        ZipFile: |
          exports.handler = (event, context, callback) => {
            console.log("Hello, logs!");
            callback(null"great success");
          };
      Role: arn:aws:iam::161715694603:role/Lambda-Dev-Role
      Runtime: "nodejs12.x"

스택 생성 및 배포

aws web console 혹은 aws-cli 를 통해서 배포할 수 있습니다.

여기서는 aws-cli 를 사용하겠습니다.

aws cloudformation create-stack --stack-name {스택 이름} --template-body file://template.yaml
$ aws cloudformation create-stack --stack-name myteststack --template-body file://template.yaml
{
    "StackId""arn:aws:cloudformation:ap-northeast-2:161715694603:stack/myteststack/31014a70-592d-11ea-aba6-06191eeb3fae"
}

web console 에서 stack 생성됨을 확인 할 수 있습니다.



스택 삭제

스택을 삭제하여 관련된 리소스를 모두 제거합니다.

aws cloudformation delete-stack --stack-name {스택 이름}
$ aws cloudformation delete-stack --stack-name myteststack

댓글

이 블로그의 인기 게시물

CDK - Assets

About VPC

dailyFocus - Frontend