Skip to content

Instantly share code, notes, and snippets.

@onuralp
Last active August 26, 2021 20:28
Show Gist options
  • Save onuralp/3abdafbd8bf28f8f9143e520922177ec to your computer and use it in GitHub Desktop.
Save onuralp/3abdafbd8bf28f8f9143e520922177ec to your computer and use it in GitHub Desktop.
Update all AWS CloudWatch log groups retention policies with AWS CLI
#!/bin/bash
echo xxxxxxxxxxxxxxxxxxxxxx Updating Retention Policies xxxxxxxxxxxxxxxxxxxxxx
RETENTION_IN_DAYS=14
AWS_REGION=us-west-2
LOG_GROUPS=$(aws logs describe-log-groups --region $AWS_REGION | jq --raw-output '.logGroups|.[]?|.logGroupName')
for logGroup in $LOG_GROUPS
do
echo EXECUTING: "Updating retention policy for ${logGroup} with ${RETENTION_IN_DAYS} day(s)"
aws logs put-retention-policy --retention-in-days $RETENTION_IN_DAYS --region $AWS_REGION --log-group-name $logGroup
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment