비용 절감을 위한 Aws instance scheduler

Hoonkii·2024년 7월 17일
0

개요

aws 클라우드 비용 최적화를 위해 dev 환경 리소스는 Working time에만 운용 되도록 하고 설정하고 싶었다.
Instance Scheduler on aws 를 활용하면 EC2, RDS 인스턴스를 태그 기반으로 손 쉽게 정해진 시간에만 운용되도록 설정할 수 있다.

설치 과정

  • CloudFormation을 통해 필요한 리소스 프로비져닝

aws 공식 문서에 정의된 CloudFomation 템플릿을 통해 Instance Scheduler on aws 에 필요한 리소스들을 프로비저닝할 수 있다.

Ref :
https://docs.aws.amazon.com/solutions/latest/instance-scheduler-on-aws/step-1-launch-the-instance-scheduler-hub-stack.html

스택을 생성하면 DynamoDB, Lambda 등의 리소스가 프로비저닝 된다.

  • Scheduler CLI 설치

링크 를 통해 cli zip을 다운받고 압축을 해제한다.

같은 디렉토리에서 다음 커맨드를 통해 scheduler-cli를 설치한다.

pip install --no-index --find-links=instance_scheduler_cli 

Ref : https://docs.aws.amazon.com/solutions/latest/instance-scheduler-on-aws/scheduler-cli-4.html

스케줄러 적용

scheduler-cli 를 통해 언제 인스턴스를 크고 켤지 period 를 생성하고, period 바탕으로 schedule 을 생성한다. 그리고 aws 리소스에 태그를 달면 스케줄러가 알아서 instance를 지정된 period 때만 구동시켜준다.

  • period 생성
scheduler-cli create-period --stack aws-rds-instance-scheduler \
 --region ap-northeast-2 \
 --name nuvi-weekdays \
 --begintime 08:00 \
 --endtime 22:00 \
 --weekdays mon-fri

월-금 오전 8시부터 오후 10시로 설정하였다.

  • schedule 생성
scheduler-cli create-schedule --stack aws-rds-instance-scheduler \
 --region ap-northeast-2 \
 --name nuvi-weekdays \
 --timezone Asia/Seoul \
 --periods nuvi-weekdays

참고로 Schedule 및 Period 데이터는 DynamoDB 에 저장된다.

  • 리소스 태그 달기

실행 로그 및 결과 확인

  • 로그 확인
    CloudFormation Stack 에 Cloudwatch 로그 그룹도 포함되어 있어, 로그를 확인할 수 있다.
    stack 이름으로 로그 그룹을 검색하면 된다.

  • 결과 확인


태그를 적용한 RDS 인스턴스의 최근 이벤트에서 Instance Scheduler 가 동작한 것을 알 수 있다.

profile
개발 공부 내용 정리

0개의 댓글