以前エンジニア組織のコスト管理おじさん業をやっていて、
その中の一つにインフラコスト管理というテーマがありました。
その時に使ってみてその後色々なプロジェクトに展開して行った手法を紹介します。
概要
staging環境など、production環境以外のRDS, EC2を夜間は停止しておいて、
朝方メンバー出社する前に起動しておく事で節約します。
コード
説明
技術スタック
- CloudFormation -> IaCというより不要になった場合に全て消せるように
- CloudWatchEvent -> スケジューラー
- CloudWatchLogs/CloudWatch -> イベントログ取得、監視
- Lambda -> インスタンスの起動、停止処理
説明
インスタンスの起動、停止処理をPythonで実装したLambdaを
CloudWatchEventで起動する。
監視をCloudWatchLogs/CloudWatchで行う。
上記の構成をCloudFormationでサクッと構築する