저번 포스팅에서 만든 yaml 파일을 통해 yaml 파일을 실행시켜보도록 하겠습니다.
콘솔로 실행시키기
1. yaml 파일 업로드
2. 디자인 확인 하기 (새 탭에서 링크 열기)

3. 스택 이름 정하기

4. 설정해 높은 파라미터 설정

- CacheNodeType : ElastiCache Node 버전
- DBInstanceClass : RDS 인스턴스 타입
- InstanceType : EC2 인스턴스 타입
- KeyName : EC2 생성할 때 만들었던 KEY(pem) 이름 입력
- MasterUserPassword : RDS 유저 비밀번호
- MasterUsername : RDS 유저 이름
5. 스택 옵션 구성
- 태그: AWS 리소스에 대한 메타데이터를 제공하는 키-값 쌍입니다. 태그를 사용하여 리소스를 분류하고, 비용 추적, 관리, 또는 보안 규칙을 적용하는 등의 용도로 활용할 수 있습니다. 예를 들어, 프로젝트 이름, 환경에 따라 태그를 붙여 리소스를 구분할 수 있습니다.
- 권한: 스택을 생성, 업데이트, 삭제할 때 사용할 AWS Identity and Access Management (IAM) 역할을 지정할 수 있습니다. 이를 통해 CloudFormation이 리소스를 대신해서 AWS API 호출을 할 수 있는 권한을 부여합니다. 특정 역할을 지정하지 않으면 CloudFormation은 스택 작업을 실행하는 데 사용된 AWS 계정의 권한을 사용합니다.
- 스택 실패 옵션: 스택 생성이 실패했을 때 리소스를 처리하는 방법을 결정합니다. 예를 들어, 실패 시 자동으로 롤백할지, 롤백하지 않고 실패한 상태를 유지할지 선택할 수 있습니다. 이를 통해 실패 원인을 분석하고 문제를 해결하는 데 도움을 받을 수 있습니다.
- 스택 정책: 특정 스택 리소스에 대한 업데이트 및 삭제 작업을 제한하는 정책입니다. 스택 정책을 통해 중요한 리소스가 실수로 변경되거나 삭제되는 것을 방지할 수 있습니다.
- 롤백 구성: 스택 생성 또는 업데이트 실패 시 CloudFormation이 롤백을 수행하는 방식을 구성합니다. 롤백 시 모니터링할 알람을 설정하고, 실패한 리소스의 스냅샷을 유지할지 여부를 결정할 수 있습니다.
- 알림 옵션: 스택 이벤트에 대한 알림을 받을 Amazon Simple Notification Service (SNS) 주제를 지정할 수 있습니다. 스택의 생성, 업데이트, 삭제 과정에서 발생하는 다양한 이벤트에 대한 알림을 받을 수 있어, 스택 상태를 효과적으로 모니터링할 수 있습니다.
- 스택 생성 옵션: 스택 생성 시 고려해야 할 추가 옵션들을 지정할 수 있습니다. 예를 들어, IAM 리소스의 생성을 허용하거나, 템플릿에서 사용할 외부 파일의 S3 위치를 지정할 수 있습니다.
Cloud9에서 CLI로 실행시키기
1. Yaml파일이 있는 폴더로 이동

2. 명령어 입력
- create-stack: 새 CloudFormation 스택을 생성합니다.
- 필수 요소
- --stack-name : 스택 이름 설정
- --template-body : yaml 파일 이름 입력
- --parameters : 파라미터 입력
- --capabilities CAPABILITY_IAM : 이 플래그는 CloudFormation 템플릿이IAM 리소스를 생성하거나 수정할 수 있는 권한을 요청
- 부가 요소
- --template-url: S3 버킷에 있는 템플릿 파일의 URL을 지정합니다. --template-body 대신 사용할 수 있으며, 크기가 큰 템플릿 파일을 사용할 때 유용합니다.
- --tags: 스택에 태그를 지정합니다. 태그는 키-값 쌍으로, 스택을 분류하고 관리하는 데 도움이 됩니다.
- --timeout-in-minutes: 스택 생성이 완료되기를 기다리는 시간을 분 단위로 설정합니다. 지정된 시간 내에 스택 생성이 완료되지 않으면, AWS CloudFormation은 스택을 자동으로 롤백(삭제)합니다.
- -on-failure: 스택 생성 실패 시 행동을 지정합니다. 가능한 값은 DO_NOTHING, ROLLBACK, **DELETE**입니다. 기본값은 **ROLLBACK**입니다.
- 필수 요소
aws cloudformation create-stack --stack-name <스택 이름> --template-body file://<템플릿 파일 경로> --parameters ParameterKey=<파라미터 이름>,ParameterValue=<파라미터 값> --capabilities CAPABILITY_IAM
- update-stack : 기존 스택을 업데이트합니다.
aws cloudformation update-stack --stack-name <스택 이름> --template-body file://<템플릿 파일 경로> --parameters ParameterKey=<파라미터 이름>,ParameterValue=<파라미터 값>
- delete-stack: 스택을 삭제합니다.
aws cloudformation delete-stack --stack-name <스택 이름>
- describe-stack : 하나 또는 여러 스택의 정보를 조회합니다.
aws cloudformation describe-stacks --stack-name <스택 이름>
- describe-stacks: 하나 또는 여러 스택의 정보를 조회합니다.
aws cloudformation describe-stacks --stack-name <스택 이름>

- list-stacks: 스택 목록을 조회합니다.
aws cloudformation list-stacks
- validate-template: CloudFormation 템플릿의 구문을 검증합니다.
aws cloudformation validate-template --template-body file://<템플릿 파일 경로>

- describe-stack-resources: 스택에 속한 리소스의 세부 정보를 조회합니다.
aws cloudformation describe-stack-resources --stack-name <스택 이름>
- get-template: 스택에 사용된 CloudFormation 템플릿의 내용을 조회합니다.aws cloudformation get-template --stack-name <스택 이름>
생성 확인

- 설정 해 놓은 출력확인

- 파라미터 확인

Chage Set
AWS CloudFormation에서 건조 실행(Dry Run)과 유사한 작업을 수행하고자 할 때는 "Change Sets" 기능을 사용할 수 있습니다.
Change Sets을 사용하면 스택에 적용하려는 변경사항을 실제로 실행하기 전에 미리 볼 수 있어, 변경이 기존 리소스에 미칠 영향을 사전에 확인할 수 있습니다.
Chage Set 생성
aws cloudformation create-change-set \\
--stack-name CF-TEST \\
--template-body file://test.yaml \\
--change-set-name MyExampleChangeSet \\
--parameters ParameterKey=InstanceType,ParameterValue=t2.small ParameterKey=KeyName,ParameterValue=CloudFormationKey ParameterKey=MasterUsername,ParameterValue=MinMagic ParameterKey=MasterUserPassword,ParameterValue=as123456 --capabilities CAPABILITY_IAM
- 현재 t2.micro인 EC2를 t2.small로 바꿔보는 Change Set을 생성

Change Set 검토
aws cloudformation describe-change-set \\
--change-set-name MyExampleChangeSet \\
--stack-name CF-TEST
- Change Set의 내용을 검토할 수 있음

Change Set 실행


aws cloudformation execute-change-set --change-set-name MyExampleChangeSet --stack-name CF-TEST
- InstanceType이 t2.micro에서 t2.small로 변경 된 것을 확인할 수 있음
'AWS Cloud School > project' 카테고리의 다른 글
CloudFormation을 TerraForm으로 변경하기 (0) | 2024.03.11 |
---|---|
CloudFormation을 이용하여 인프라 관리 Yaml 파일 생성 (0) | 2024.03.02 |
DMZ 구성 (0) | 2024.02.01 |
CentOS에서 보안 회선 VPN 구성 (실습) (2) | 2024.01.21 |