Last active
October 15, 2023 02:31
-
-
Save datahaikuninja/eef0d50b9551ee0ce60de06b62e41772 to your computer and use it in GitHub Desktop.
My aws cli logs command cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CloudWatchLogsのAWS CLIチートシート |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# log_group_list.csvにロググループ名と保持期間を書く | |
set -euxo pipefail | |
while IFS=, read -r log_group_name retension_in_days | |
do | |
aws logs put-retention-policy \ | |
--log-group-name "${log_group_name}" \ | |
--retention-in-days "${retension_in_days}" \ | |
--region ap-northeast-1 | |
done < log_group_list.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CloudWatchのコスト削減のために、データ量が多い順にロググループをソートするコマンド | |
# スプレッドシートに貼り付ける想定でcsvで出力している | |
# --query の配列の後ろの辞書はなくても構わない | |
# reverse(sort_by())によって降順でソートした配列をjqに渡しても結果のcsvは変わらない | |
aws logs describe-log-groups \ | |
--no-paginate \ | |
--query 'reverse(sort_by(logGroups, &storedBytes))[].{"logGroupName": logGroupName, "storedBytes": storedBytes, "retentionInDays": retentionInDays}' \ | |
--output json | jq -r ".[] | [.logGroupName, .storedBytes, .retentionInDays] | @csv" > log-groups.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment