0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS CLIでCloudWatchLogsのロググループの保持期間を一括更新しよう

Last updated at Posted at 2024-01-15

はじめに

CloudWatchLogsのロググループにログがたまり続けると、AWS利用料が密かに上がってしまいます。

AWS CLIを用いて一括更新するシェルスクリプトを作ってみました。

スクリプト

update_log_retention.sh
#!/bin/sh

cd `dirname $0`

# 保持期間を1日にしています。
RETENTION_IN_DAYS=1
REGION=ap-northeast-1

LOG_GROUPS=$(
  aws logs describe-log-groups \
    --query "logGroups[].logGroupName" \
    --output text \
    --region ${REGION}
  )

for LOG_GROUP in ${LOG_GROUPS}
do
  aws logs put-retention-policy \
    --log-group-name ${LOG_GROUP} \
    --retention-in-days ${RETENTION_IN_DAYS} \
    --region ${REGION}
done

exit 0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?