Last active
June 6, 2024 14:07
-
-
Save mkjsix/93398280b32aebb7e5379b40e8598b71 to your computer and use it in GitHub Desktop.
Set retention policies for AWS CloudWatch Log Groups, for a profile and a region
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 | |
# Example - to set the logs retention policy for your default AWS account in region eu-west-1 to 5 days, execute the command: | |
# set-retention.sh default eu-west-1 5 | |
export AWS_PROFILE=$1 | |
export AWS_REGION=$2 | |
RETENTION_DAYS=${3:-30} | |
echo "AWS_PROFILE=$AWS_PROFILE, AWS_REGION=$AWS_REGION, RETENTION_DAYS=$RETENTION_DAYS" | |
while read -r i; | |
do (aws logs put-retention-policy --region "$AWS_REGION" --log-group-name "$i" --retention-in-days "$RETENTION_DAYS" ); | |
done < <(aws logs describe-log-groups --region "$AWS_REGION" --query 'logGroups[*].[logGroupName]' | grep / | sed 's/"//g') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment