Skip to content

Instantly share code, notes, and snippets.

@mkjsix
Last active October 18, 2019 07:26
Show Gist options
  • Save mkjsix/1b2b4f8221bd4ed8f14a68abd45e9b91 to your computer and use it in GitHub Desktop.
Save mkjsix/1b2b4f8221bd4ed8f14a68abd45e9b91 to your computer and use it in GitHub Desktop.
Read retention policies for AWS CloudWatch Log Groups, for a profile and a region
#!/bin/bash
# Example - to read the logs retention policy for your default AWS account in region eu-west-1, execute the command:
# read-retention.sh default eu-west-1
export AWS_PROFILE=$1
export AWS_REGION=$2
echo "AWS_PROFILE=$AWS_PROFILE, AWS_REGION=$AWS_REGION"
while read -r i;
do (printf "%s: " "$i" && aws logs describe-log-groups --region "$AWS_REGION" --log-group-name-prefix "$i" --query 'logGroups[0].retentionInDays');
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