インストール方法
- AWS 公式から AWS CLI MSI インストーラ をダウンロード
- ダウンロードしたインストーラを実行して端末にインストールする
- インストール後にコマンドプロンプトで以下を実行し、インストールできたか確認する
$ aws --version
aws-cli/2.8.10 Python/3.9.11 Windows/10 exe/AMD64 prompt/off
設定
以下の方法でユーザ情報を設定する
$ aws configure
AWS Access Key ID [None]: {アクセスキー}
AWS Secret Access Key [None]: {シークレットアクセスキー}
Default region name [None]: ap-northeast-1
Default output format [None]: json
使い方
- 指定したインスタンスIDで取得できるメトリクスの一覧を表示
$ aws cloudwatch list-metrics --namespace AWS/EC2 --dimensions Name=InstanceId,Value=i-xxxxxxxxxxxxxxxxx
- CPUUtilization を指定した期間(+9時間)、5分間の粒度、指定したインスタンスID、平均値をタブ区切りでファイルに出力する方法
$ aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --start-time yyyy-mm-ddTHH:MM:SS+09 --end-time yyyy-mm-ddTHH:MM:SS+09 --period 300 --dimensions Name=InstanceId,Value=i-xxxxxxxxxxxxxxxxx --statistics Average --output table > log.txt