Created
March 1, 2024 06:18
-
-
Save tpschmidt/ff3da01863e304b91ecc08e7e41464da to your computer and use it in GitHub Desktop.
Set Retention for all AWS CloudWatch Log Groups in all Regions
This file contains hidden or 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 | |
| retention_days=$1 | |
| if [ -z "$retention_days" ]; then | |
| echo "Usage: $0 <retention_days>" | |
| exit 1 | |
| fi | |
| regions=$(aws ec2 describe-regions \ | |
| --query 'Regions[*].RegionName' \ | |
| --output text | |
| ) | |
| for region in $regions; do | |
| ( | |
| echo "Processing region: $region" | |
| log_groups=$(aws logs describe-log-groups \ | |
| --region "$region" \ | |
| --query 'logGroups[*].logGroupName' \ | |
| --output text | |
| ) | |
| for log_group in $log_groups; do | |
| echo "[$region] Updating $log_group" | |
| aws logs put-retention-policy \ | |
| --region "$region" \ | |
| --log-group-name "$log_group" \ | |
| --retention-in-days "$retention_days" | |
| done | |
| ) & | |
| done | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment